Jeyahariprakash
Jeyahariprakash

Reputation: 70

OkHttp ".string" not closing the process

I am trying to print the response body by using OKHttp interceptor at Retrofit webservice call .Please find the interceptor below

    public class ResponseValidationInterceptor implements Interceptor {

    public static final String TAG = "ResponseValidationInterceptor";

    @Inject
    public ResponseValidationInterceptor() {
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        Log.e(TAG, "resposne --->" + originalResponse.body().string());
        return originalResponse;
    }

}

At above interceptor if I commented the line Log.e everything works fine. Else, originalResponse.body.string() not closing the process. At its not moving to next line. If any one know about solution please help me. Thanks in advance

Upvotes: 0

Views: 53

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40587

You probably don’t want to log the response body directly. The response body is a one-shot stream, and reading it in an interceptor prevents the original caller of this request from being able to access it.

Using OkHttp’s logging interceptor might be a better choice.

Upvotes: 0

Related Questions