同步retrofit中如何获取http响应状态2
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();
您可以将其存储在Response类型中,然后执行。 Response 提供了通过 .code() 方法检索代码的功能。
Response response = call1.execute();
System.out.println(response.code());
hd = (HotelDetail) response.body();
System.out.println(hd.toString());
我正在从服务器获得响应,使用改造 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();
您可以将其存储在Response类型中,然后执行。 Response 提供了通过 .code() 方法检索代码的功能。
Response response = call1.execute();
System.out.println(response.code());
hd = (HotelDetail) response.body();
System.out.println(hd.toString());