我正在使用改造从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字符串。 –