使用OkHttp上传文件,但发生java.lang.IllegalStateException:在okio.RealBufferedSink.write处关闭(RealBufferedSink.java:44)

时间:2016-05-19 09:28:09

标签: android file-upload okhttp

问题是标题所说的。它有时只出现一些电话。听到我抓到的日志。

java.lang.IllegalStateException
closed
okio.RealBufferedSink.write(RealBufferedSink.java:44)
okio.ForwardingSink.write(ForwardingSink.java:35)
com.******.******.network.UploadRequestBody$1.write(UploadRequestBody.java:75)
okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
okio.RealBufferedSink.writeAll(RealBufferedSink.java:104)
com.squareup.okhttp.RequestBody$3.writeTo(RequestBody.java:118)
com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeOrCountBytes(MultipartBuilder.java:277)
com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeTo(MultipartBuilder.java:297)
com.******.******.network.UploadRequestBody.writeTo(UploadRequestBody.java:59)
com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:718)
com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576)
com.squareup.okhttp.Call.getResponse(Call.java:287)
com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
com.squareup.okhttp.Call.access$100(Call.java:35)
com.squareup.okhttp.Call$AsyncCall.execute(Call.java:171)
com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
java.lang.Thread.run(Thread.java:848)

你介意帮助我并说明如何避免它吗?

1 个答案:

答案 0 :(得分:1)

我在github issue

找到了这个

您只能拨打response.body().string()一次。