我在okhttp响应中得到40MB数据。并且需要花费超过25秒的responseStr = response.body().string()
来处理。任何人都可以帮助我减少处理时间。
private String okhttpPost(String xmlRequest) {
String responseStr = null;
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(Level.BASIC);
OkHttpClient client = new OkHttpClient().newBuilder().addInterceptor(logging).connectTimeout(60, TimeUnit.SECONDS).writeTimeout(60, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).build();
RequestBody formBody = new FormBody.Builder().add("XML", xmlRequest).build();
Request request = new Request.Builder().url("https://consumerfed/itsection/findData").post(formBody).addHeader("Content-Type", "application/x-www-form-urlencoded").addHeader("Connection", "Keep-Alive").addHeader("Accept-Language", "en-US").addHeader("Accept-Encoding", "application/gzip").build();
try {
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
responseStr = response.body().string();
}
} catch (IOException exception) {
exception.printStackTrace();
}
return responseStr;
}