Get Raw Response Of Retrofit 2 Request

  • Posted on: 10 February 2018
  • By: robin

A widely discoussed problem on StackOverflow is how one gets the raw string from the respone of a Retrofit 2 request. The Approache with intercepting or using the enqueue() function does not work really well. Once the Reponse is created for the first time the enqueue function will throw an error that it can not get the content since it was already consumed. 

So but one now ? Maybe you know that Retrofit is using okhttp3. The cool thing is we can send requests directly with an OkHttpClient instance. 

//raw text 
Request request = call.clone().request();
OkHttpClient client = new OkHttpClient();
okhttp3.Response test = client.newCall(request).execute();
System.out.println(test.body().string());
topic: 
java, okhttp3, retrofit, programming, code
Field: 

Comments

A lot of developers are having a strong competition to learn such techniques to innitiate what is needed the most on the regular basis as per the demands of the customers.