0%

okhttp异常: java.lang.IllegalStateException: closed

1
2
3
4
5
6
7
8
9
10
11
09-05 14:42:17.606: E/AndroidRuntime(28219): Caused by: java.lang.IllegalStateException: closed
09-05 14:42:17.606: E/AndroidRuntime(28219): at okhttp3.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:414)
09-05 14:42:17.606: E/AndroidRuntime(28219): at okio.Buffer.writeAll(Buffer.java:993)
09-05 14:42:17.606: E/AndroidRuntime(28219): at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:106)
09-05 14:42:17.606: E/AndroidRuntime(28219): at okhttp3.ResponseBody.bytes(ResponseBody.java:128)
09-05 14:42:17.606: E/AndroidRuntime(28219): at okhttp3.ResponseBody.string(ResponseBody.java:154)
09-05 14:42:17.606: E/AndroidRuntime(28219): at com.example.nettest.MainActivity$MyAsyncTask.doInBackground(MainActivity.java:78)
09-05 14:42:17.606: E/AndroidRuntime(28219): at com.example.nettest.MainActivity$MyAsyncTask.doInBackground(MainActivity.java:1)
09-05 14:42:17.606: E/AndroidRuntime(28219): at android.os.AsyncTask$2.call(AsyncTask.java:292)
09-05 14:42:17.606: E/AndroidRuntime(28219): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-05 14:42:17.606: E/AndroidRuntime(28219): ... 4 more

这个错误是由于response.body().string()调用了多次导致的,string()仅可调用一次。