Get Raw Response Of Retrofit 2 Request

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

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

This site uses Akismet to reduce spam. Learn how your comment data is processed.