public static String getResponseBody(Response response) { Charset UTF8 = Charset.forName("UTF-8"); ResponseBody responseBody = response.body(); BufferedSource source = responseBody.source(); try { source.request(Long.MAX_VALUE); // Buffer the entire body. } catch (IOException e) { e.printStackTrace(); } Buffer buffer = source.buffer(); Charset charset = UTF8; MediaType contentType = responseBody.contentType(); if (contentType != null) { try { charset = contentType.charset(UTF8); } catch (UnsupportedCharsetException e) { e.printStackTrace(); } } return buffer.clone().readString(charset); }
body.string()会截断流