Retrofit 2.0 GET请求 报错 ECONNRESET (Connection reset by peer)
澳门银河官网
澳门银河官网
当前位置 : 澳门银河官网 > 澳门银河官网开户

Retrofit 2.0 GET请求 报错 ECONNRESET (Connection reset by peer)

我的应用使用 Retrofit 2.0 调用服务端的api接口,我在wifi网络下测试都好了,然后用4G网络测试就报了这个错误。而且是只有GET请求有这个错误 POST请求是好的。

代码:

Request request = chain.request;
                Response response = null;
                int tryCount = 0;
                do {
                    tryCount++;
                    try {
                        response = chain.proceedrequest.newBuilder.addHeader"Authorization", token
                                .addHeader"Content-Type", "application/json;charset=UTF-8"
                                .addHeader"Connection", "keep-alive"
                                .build;
                    } catch IOException e {
                        //异常在这里报的
                        e.printStackTrace;
                    }
                } while response==null || !response.isSuccessful && tryCount < 3;

                return response;

具体异常信息:

06-28 13:32:07.718 30243-30322/ W/System.err: java.net.SocketException: recvfrom failed: ECONNRESET Connection reset by peer
06-28 13:32:07.720 30243-30322/ W/System.err:     at libcore.io.IoBridge.maybeThrowAfterRecvfromIoBridge.java:592
06-28 13:32:07.720 30243-30322/ W/System.err:     at libcore.io.IoBridge.recvfromIoBridge.java:556
06-28 13:32:07.720 30243-30322/ W/System.err:     at java.net.PlainSocketImpl.readPlainSocketImpl.java:485
06-28 13:32:07.720 30243-30322/ W/System.err:     at java.net.PlainSocketImpl.access$000PlainSocketImpl.java:37
06-28 13:32:07.720 30243-30322/ W/System.err:     at java.net.PlainSocketImpl$PlainSocketInputStream.readPlainSocketImpl.java:237
06-28 13:32:07.720 30243-30322/ W/System.err:     at okio.Okio$2.readOkio.java:139
06-28 13:32:07.720 30243-30322/ W/System.err:     at okio.AsyncTimeout$2.readAsyncTimeout.java:211
06-28 13:32:07.720 30243-30322/ W/System.err:     at okio.RealBufferedSource.indexOfRealBufferedSource.java:306
06-28 13:32:07.720 30243-30322/ W/System.err:     at okio.RealBufferedSource.indexOfRealBufferedSource.java:300
06-28 13:32:07.720 30243-30322/ W/System.err:     at okio.RealBufferedSource.readUtf8LineStrictRealBufferedSource.java:196
06-28 13:32:07.720 30243-30322/ W/System.err:     at okhttp3.internal.http.Http1xStream.readResponseHttp1xStream.java:184
06-28 13:32:07.720 30243-30322/ W/System.err:     at okhttp3.internal.http.Http1xStream.readResponseHeadersHttp1xStream.java:125
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.internal.http.HttpEngine.readNetworkResponseHttpEngine.java:723
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.internal.http.HttpEngine.access$200HttpEngine.java:81
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceedHttpEngine.java:708
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.internal.http.HttpEngine.readResponseHttpEngine.java:563
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.RealCall.getResponseRealCall.java:241
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.RealCall$ApplicationInterceptorChain.proceedRealCall.java:198
06-28 13:32:07.721 30243-30322/ W/System.err:     at .core.api.RetrofitRestClient$2.interceptRetrofitRestClient.java:120
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.RealCall$ApplicationInterceptorChain.proceedRealCall.java:187
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChainRealCall.java:160
06-28 13:32:07.721 30243-30322/ W/System.err:     at okhttp3.RealCall.executeRealCall.java:57
06-28 13:32:07.721 30243-30322/ W/System.err:     at retrofit2.OkHttpCall.executeOkHttpCall.java:174
06-28 13:32:07.721 30243-30322/ W/System.err:     at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.requestRxJavaCallAdapterFactory.java:171
06-28 13:32:07.721 30243-30322/ W/System.err:     at rx.internal.operators.OperatorSubscribeOn$1$1$1.requestOperatorSubscribeOn.java:80
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.Subscriber.setProducerSubscriber.java:211
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.internal.operators.OperatorSubscribeOn$1$1.setProducerOperatorSubscribeOn.java:76
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.Subscriber.setProducerSubscriber.java:205
06-28 13:32:07.722 30243-30322/ W/System.err:     at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.callRxJavaCallAdapterFactory.java:152
06-28 13:32:07.722 30243-30322/ W/System.err:     at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.callRxJavaCallAdapterFactory.java:138
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.Observable$2.callObservable.java:162
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.Observable$2.callObservable.java:154
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.Observable.unsafeSubscribeObservable.java:8314
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.internal.operators.OperatorSubscribeOn$1.callOperatorSubscribeOn.java:94
06-28 13:32:07.722 30243-30322/ W/System.err:     at rx.internal.schedulers.ScheduledAction.runScheduledAction.java:55
06-28 13:32:07.722 30243-30322/ W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.callExecutors.java:422
06-28 13:32:07.722 30243-30322/ W/System.err:     at java.util.concurrent.FutureTask.runFutureTask.java:237
06-28 13:32:07.722 30243-30322/ W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201ScheduledThreadPoolExecutor.java:152
06-28 13:32:07.722 30243-30322/ W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runScheduledThreadPoolExecutor.java:265
06-28 13:32:07.723 30243-30322/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorkerThreadPoolExecutor.java:1112
06-28 13:32:07.723 30243-30322/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.runThreadPoolExecutor.java:587
06-28 13:32:07.723 30243-30322/ W/System.err:     at java.lang.Thread.runThread.java:818
06-28 13:32:07.723 30243-30322/ W/System.err: Caused by: android.system.ErrnoException: recvfrom failed: ECONNRESET Connection reset by peer

you can like this

广告位

澳门银河官网