Я пытался сделать это, добавив перехватчик в Retrofit в качестве NetworkInterceptor, однако возвращенная строка не имела формата.
Код: Выделить всё
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
try {
final String responseString = new String(response.body().bytes() );
LOGD("OkHttp-NET-Interceptor", "Response: " + responseString);
String newResponseString = editResponse( responseString );
LOGD("OkHttp-NET-Interceptor", "Response edited: " + newResponseString);
return response.newBuilder()
.body(ResponseBody.create(response.body().contentType(), newResponseString))
.build();
}catch (Exception ex){
return response;
}
}
После перехода на обычный перехватчик строка имела формат a, который можно было преобразовать в JSONObject.
Может ли кто-нибудь сказать мне, в чем различия между ответами?
почему эта строка new String(response.body().bytes() ); возвращает другое содержимое?
Подробнее здесь: https://stackoverflow.com/questions/371 ... erceptor-f
Мобильная версия