Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit2.0 is returning 404 not found

 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.

like image 840
HugoXie Avatar asked Oct 21 '25 13:10

HugoXie


1 Answers

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.

like image 123
EpicPandaForce Avatar answered Oct 24 '25 04:10

EpicPandaForce