I am using Retrofit / Robospice to make api calls in the application I created with RetrofitGsonSpiceService. All responses are converted to POJO using the GSON converter, however there is some information that I need to get from the response header. I can’t find any means to get the headers (I can only get the headers if the request is unsuccessful because the original response was sent to the error object!), How can I intercept the answer to capture the headers before converting it ?
It took me a few minutes to figure out exactly what @mato suggested in his answer. Here is a concrete example of how to replace OkClientthat comes with Retrofit to intercept response headers.
OkClient
public class InterceptingOkClient extends OkClient { public InterceptingOkClient() { } public InterceptingOkClient(OkHttpClient client) { super(client); } @Override public Response execute(Request request) throws IOException { Response response = super.execute(request); for (Header header : response.getHeaders()) { // do something with header } return response; } }
Then you pass the instance of your user client to RestAdapter.Builder:
RestAdapter.Builder
RestAdapter restAdapter = new RestAdapter.Builder() .setClient(new InterceptingOkClient()) .... .build();
RoboSpice , HTTP-, . HTTP-. Retrofit Apache, OkHttp HTTP Android, , . , Retrofit HTTP- (. , ), .
Retrofit Client. , , : ApacheClient, OkClient UrlConnectionClient. , , , , .
Client
ApacheClient
UrlConnectionClient
, Client .
Source: https://habr.com/ru/post/1542219/More articles:SublimeREPL + Octave - sublimetext2Voting / messaging system for messages using MySQL - phpYAML :: Dumper not quoting scalar string "-" - ruby | fooobar.comУдивительный генератор шрифта - gruntjsenv.getProperty not working Spring PropertyPlaceholderConfigurer - javacreateDestinationInstancesForSourceInstance не вызывается - core-dataGiving user access to specific models in admin - djangoТупиковые блоки при использовании блоков данных BlockingCollection и TPL вместе - multithreadingDeserializing enum Shape.OBJECT using Jackson not working - javaswig cannot find openssl conf - pythonAll Articles