当我将文件发布到服务器时,我尝试在文件上传成功时从服务器获取结果,但是当我这样做时,它会抛出异常,有我的代码
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("upload", "upload fail" + e.toString());
e.printStackTrace();
removeRequest(tag);
listener.onUploadFail();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
Log.e("upload", "upload success" + response.body().string());
listener.onUploadSuccess(response.message());
removeRequest(tag);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
});
有例外
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: java.lang.IllegalStateException: closed
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:378)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at okio.Buffer.writeAll(Buffer.java:956)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:92)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at okhttp3.ResponseBody.bytes(ResponseBody.java:83)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at okhttp3.ResponseBody.string(ResponseBody.java:109)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at com.gzkit.workmap.kithttpmanager.core.KitHttpManager$4.onResponse(KitHttpManager.java:1084)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-23 16:37:24.047 19334-19462/com.gzkit.DianJianPlatform W/System.err: at java.lang.Thread.run(Thread.java:841)