Android OkHttp切断了长响应
我需要使用clientAndroid OkHttp切断了长响应,android,http,get,okhttp,okhttp3,Android,Http,Get,Okhttp,Okhttp3,我需要使用clientOkHttpClient(OkHttp3)获取html页面的源代码。 为此,应使用以下代码: @Override public String loadInBackground() { try { HttpLoggingInterceptor mLogging = new HttpLoggingInterceptor(); mLogging.setLevel(HttpLoggingIntercep
OkHttpClient
(OkHttp3)获取html页面的源代码。
为此,应使用以下代码:
@Override
public String loadInBackground() {
try {
HttpLoggingInterceptor mLogging = new HttpLoggingInterceptor();
mLogging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient mClient = new OkHttpClient.Builder().addInterceptor(mLogging).build();
Request mRequest = new Request.Builder()
.url("some url")
.build();
Response mResponse = mClient.newCall(mRequest).execute();
Log.i(TAG, "loadInBackground: " + mResponse.body().string());
return mResponse.body().string();
} catch (IOException e) {
return new String();
}
}
它可以工作,但只返回250个字符多一点,代码超过9500个字符。如何获得完整的回复?另外,日志是使用HttpLoggingInterceptor获取的,它显示完整的响应。
日志语句不会打印整个字符串
确定字符串长度并打印以查看。您的意思是什么?我定义了字符串的长度
response.body().string().length()
,但如何在日志中显示整个字符串?我定义了字符串响应的长度.body().string().length()
。你的意思是:我用response.body().string().length()确定了字符串的长度。
?那么它的长度是多少?