如何在同步改造2中获取http响应状态 [英] How to get http response status in synchronous retrofit 2

查看:90
本文介绍了如何在同步改造2中获取http响应状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用改良版2.0.1从服务器正确地获得响应,是否有任何方法可以在不使用异步方法的情况下获取HTTP响应状态?

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

推荐答案

您可以将其存储为Response类型,然后执行.响应提供了通过.code()方法检索代码的功能.

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

这篇关于如何在同步改造2中获取http响应状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆