本文介绍了Retrofit2.0 返回 404 not found的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("ipAdress/SaveImg/DouBanGirl")
.addConverterFactory(GsonConverterFactory.create())
.build();
imgApi imgService = retrofit.create(imgApi.class);
Call<Img> imgCall = imgService.getImg("20151119");
imgCall.enqueue(new Callback<Img>() {
@Override
public void onResponse(retrofit.Response<Img> response, Retrofit retrofit) {
Log.d(TAG, response.code() + " ");
}
@Override
public void onFailure(Throwable t) {
Log.d(TAG, t.getMessage());
}
});
}
public interface imgApi {
@GET("/DouBanGirl")
Call<Img> getImg(@Query("date") String date);
}
当我尝试此操作时,它显示未找到 404.网址是正确的,我检查过.我不知道发生了什么.
when i tried this, it is showing 404 not found. the url is correct, i checked that. I dont know what going on.
推荐答案由于 Retrofit 2.0 如何使用 Http Resolve 来解析端点的 uri 方案,如果您像这样指定 baseurl hello 和端点 URL 为 /world/foo 它会中断.
Due to how Retrofit 2.0 uses Http Resolve for resolving the uri scheme of your endpoints, if you specify the baseurl like this hello and the endpoint URL as /world/foo it will break.
您需要使用基本 URL hello/ 和端点 URL world/foo.
You need to use base URL hello/ and endpoint URL world/foo.
/ 有所作为.
更多推荐
Retrofit2.0 返回 404 not found
发布评论