Retrofit2.0 is returning 404 not found

巧了我就是萌 提交于 2019-12-12 10:16:45

问题


 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!