How to get http response status in synchronous retrofit 2

懵懂的女人 提交于 2019-12-12 17:32:29

问题


I am getting the response from the server all right, using retrofit 2.0.1, Is there any way to get the HTTP response status, without using Asynchronous method?

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://192.168.8.4/********/***/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RequestInterface request = retrofit.create(RequestInterface.class);
        HotelDetail hd;

        Call<HotelDetail> call1 = request.getIndividualHotel("1");

       hd = call1.execute().body();

回答1:


You can store it in Response type and then execute it. Response provides the functionality to retrieve codes via .code() method.

Response response = call1.execute();
    System.out.println(response.code());
    hd = (HotelDetail) response.body();
    System.out.println(hd.toString());


来源:https://stackoverflow.com/questions/36425488/how-to-get-http-response-status-in-synchronous-retrofit-2

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