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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With