How to change body in OkHttp Response?

前端 未结 5 2021
清酒与你
清酒与你 2021-02-01 06:05

I\'m using retrofit. To catch response i\'m using Interceptor:

OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.interceptors().add(myinterceptor);
         


        
5条回答
  •  一向
    一向 (楼主)
    2021-02-01 06:41

    Add this

    MediaType contentType = response.body().contentType();
    ResponseBody body = ResponseBody.create(contentType, jsonObject);
    return response.newBuilder().body(body).build();
    

    after your response modification. jsonObject is the modified JSON you want to return.

提交回复
热议问题