问题
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://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);
}
when i tried this, it is showing 404 not found. the url is correct, i checked that. I dont know what going on.
回答1:
Due to how Retrofit 2.0 uses Http Resolve for resolving the uri scheme of your endpoints, if you specify the baseurl like this http://hello.com and the endpoint URL as /world/foo it will break.
You need to use base URL http://hello.com/ and endpoint URL world/foo.
The / makes the difference.
来源:https://stackoverflow.com/questions/34206172/retrofit2-0-is-returning-404-not-found