android – java.net.SocketTimeoutException:timeout

android – java.net.SocketTimeoutException:timeout,第1张

概述使用OkHttp库,应用程序面临以下SocketTimeoutException问题.如果请求大小较小,那么它工作正常(小于1MB).我在10秒内收到这个异常,即使我的套接字超时(readTimeout)值要高得多.一直是失败的请求(大小是1.8MB).当我使用HttpUrlConnection执行请求时,它工作正常.什么可能是失败的可能原因? 03-29 12:16:38.997 32066-4 使用Okhttp库,应用程序面临以下SocketTimeoutException问题.如果请求大小较小,那么它工作正常(小于1MB).我在10秒内收到这个异常,即使我的套接字超时(readTimeout)值要高得多.一直是失败的请求(大小是1.8MB).当我使用httpUrlConnection执行请求时,它工作正常.什么可能是失败的可能原因?
03-29 12:16:38.997 32066-4018/com.mobile W/System.err: java.net.socketTimeoutException: timeout    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okio.Okio.newTimeoutException(Okio.java:207)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okio.AsyncTimeout.exit(AsyncTimeout.java:261)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okio.AsyncTimeout.write(AsyncTimeout.java:158)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okio.RealBufferedSink.write(RealBufferedSink.java:46)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okhttp3.internal.http.http1xStream$FixedLengthSink.write(http1xStream.java:286)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okio.RealBufferedSink.write(RealBufferedSink.java:96)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okhttp3.Requestbody.writeto(Requestbody.java:96)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okhttp3.internal.http.httpEngine$NetworkInterceptorChain.proceed(httpEngine.java:704)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okhttp3.internal.http.httpEngine.readResponse(httpEngine.java:563)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okhttp3.RealCall.getResponse(RealCall.java:241)    03-29 12:16:38.997 32066-4018/com.mobile W/System.err:     at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at okhttp3.RealCall.execute(RealCall.java:57)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at com.mobizio.API.BaseAPI.sendOkhttpRequest(BaseAPI.java:81)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at com.mobizio.API.BaseAPI.doInBackground(BaseAPI.java:45)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at com.mobizio.API.BaseAPI.doInBackground(BaseAPI.java:30)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at androID.os.AsyncTask.call(AsyncTask.java:292)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at java.lang.Thread.run(Thread.java:818)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err: Caused by: java.net.socketException: socket is closed    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at com.androID.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:759)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at okio.Okio.write(Okio.java:80)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:     at okio.AsyncTimeout.write(AsyncTimeout.java:155)    03-29 12:16:38.998 32066-4018/com.mobile W/System.err:  ... 20 more
解决方法 对于Okhttp 3,Okhttp的默认值为10秒.您可以将超时增加到30秒.
OkhttpClIEnt clIEnt = new OkhttpClIEnt();clIEnt.setConnectTimeout(30,TimeUnit.SECONDS); // connect timeoutclIEnt.setReadTimeout(30,TimeUnit.SECONDS);    // socket timeout
总结

以上是内存溢出为你收集整理的android – java.net.SocketTimeoutException:timeout全部内容,希望文章能够帮你解决android – java.net.SocketTimeoutException:timeout所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1132634.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存