我正在使用改造從http URL獲取數據。 我的接口類別:在改造中接收空體迴應
public interface SlotsAPI {
/*Retrofit get annotation with our URL
And our method that will return a Json Object
*/
@GET(url)
retrofit.Call<JSONObject> getSlots();
}
我的請求方法。
public void getResponse(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
//Creating an object of our api interface
SlotsAPI api = retrofit.create(SlotsAPI.class);
retrofit.Call<JSONObject> callback = api.getSlots();
callback.enqueue(new Callback<JSONObject>() {
@Override
public void onResponse(Response<JSONObject> response) {
if (response != null) {
Log.d("OnResponse", response.body().toString());
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
});
}
在響應中,我收到一個空的body.And服務器響應200 OK。
D/OnResponse: {}
但是當我在瀏覽器中打開URL時,我在屏幕上獲取JSONObject。
你可以提供網址嗎? –
對不起,我不能。但它是一個普通的http鏈接。 – Viking93
我建議你使用諸如Fiddler或Charles之類的工具,並通過它們代理這兩種流量。然後,您可以比較請求中的差異並獲得想法。 也許是因爲UserAgent字符串。 –