Web services java.io.EOFException:Reformation 2.0中第1行第1列的输入结束
我不知道问题出在哪里Web services java.io.EOFException:Reformation 2.0中第1行第1列的输入结束,web-services,gson,retrofit2,android-studio-2.2,Web Services,Gson,Retrofit2,Android Studio 2.2,我不知道问题出在哪里 { "success": "1", "wallpapers": [ { "id": "1", "image": "http://cyphersol.com/apps/ringtona/uploads/gallery/1477685052.jpg" }, { "id": "2", "image": "http://cyphersol.com/apps/ringtona/uploads/galler
{
"success": "1",
"wallpapers": [
{
"id": "1",
"image": "http://cyphersol.com/apps/ringtona/uploads/gallery/1477685052.jpg"
},
{
"id": "2",
"image": "http://cyphersol.com/apps/ringtona/uploads/gallery/14776850521.jpg"
},
{
"id": "3",
"image": "http://cyphersol.com/apps/ringtona/uploads/gallery/14776850522.jpg"
},
{
"id": "4",
"image": "http://cyphersol.com/apps/ringtona/uploads/gallery/14776850523.jpg"
},
{
"id": "5",
"image": "http://cyphersol.com/apps/ringtona/uploads/gallery/14776850524.jpg"
}
]
}
我正在使用2.0
接口
public interface ApiInterface {
@POST("getImages")
Call<WallPaperResponse> getWallpapers(@Query("id") int apiKey);
}
呼叫主活动
ApiInterface apiService =
ApiClient.getClient().create(ApiInterface.class);
Call<WallPaperResponse> call = apiService.getWallpapers(1);
call.enqueue(new Callback<WallPaperResponse>() {
@Override
public void onResponse(Call<WallPaperResponse> call, Response<WallPaperResponse> response) {
int statusCode = response.code();
List<WallpapersItem> wallpaper = response.body().getWallpapers();
for (int i = 0; i < wallpaper.size(); i++) {
Log.e(TAG, wallpaper.get(i).getImage());
}
// recyclerView.setAdapter(new MoviesAdapter(movies, R.layout.list_item_movie, getApplicationContext()));
}
@Override
public void onFailure(Call<WallPaperResponse> call, Throwable t) {
// Log error here since request failed
Log.e(TAG, t.toString());
}
});
我想这对你有帮助 KingController mWebController=KingController.getInstance(此); 字符串apiToken=“1”;mWebController.getMainCategories(apiToken) @获取(“获取图像”) 调用getwallperlis(@Header(“id”)字符串api_令牌) 雷加格斯
Rashid Ali您的web服务要求将id作为标头发送 而您宁愿将其作为POST参数发送。 因此,您的web服务没有返回有效的响应 还有错误 让我知道这是否有效
public interface ApiInterface {
@GET("getImages")
Call<WallPaperResponse> getWallpapers(@Header("id") int apiKey);
}
公共接口{
@获取(“获取图像”)
调用getWallpapers(@Header(“id”)int-apiKey);
}
这个网站有关于RetroFit的可靠文档
// retrofit, gson
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
public interface ApiInterface {
@GET("getImages")
Call<WallPaperResponse> getWallpapers(@Header("id") int apiKey);
}