簡體   English   中英

如何在同步改造2中獲得http響應狀態

[英]How to get http response status in synchronous retrofit 2

我正在使用改良版2.0.1從服務器獲得響應,可以使用不使用異步方法的任何方法來獲取HTTP響應狀態嗎?

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();

您可以將其存儲為“響應”類型,然后執行它。 響應提供了通過.code()方法檢索代碼的功能。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM