流被重置:PROTOCOL_ERROR,同时在3G网络中使用Retrofit

时间:2014-11-17 10:52:05

标签: android networking retrofit okhttp

大家中午好!

我在我的应用程序中使用Retrofit进行网络呼叫。该应用程序真的很好,速度很快。感谢精彩的图书馆。但是,它只适用于Wi-Fi。如果我在3G网络中运行应用程序,则抛出错误。 stream was reset: PROTOCOL_ERROR, while using Retrofit in 3G network

我已将此jar文件导入构建路径:

enter image description here

这是完整的堆栈跟踪:

11-17 16:01:54.017: D/Retrofit(3595): java.io.IOException: stream was reset: PROTOCOL_ERROR
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.spdy.SpdyStream.getResponseHeaders(SpdyStream.java:146)
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.http.SpdyTransport.readResponseHeaders(SpdyTransport.java:109)
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:676)
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:426)
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:371)
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:466)
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
11-17 16:01:54.017: D/Retrofit(3595):   at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
11-17 16:01:54.017: D/Retrofit(3595):   at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73)
11-17 16:01:54.017: D/Retrofit(3595):   at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
11-17 16:01:54.017: D/Retrofit(3595):   at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
11-17 16:01:54.017: D/Retrofit(3595):   at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
11-17 16:01:54.017: D/Retrofit(3595):   at $Proxy0.getLoginCredentials(Native Method)
11-17 16:01:54.017: D/Retrofit(3595):   at com.connected.merchant.SignIn$SignMeIn.doInBackground(SignIn.java:197)
11-17 16:01:54.017: D/Retrofit(3595):   at com.connected.merchant.SignIn$SignMeIn.doInBackground(SignIn.java:1)
11-17 16:01:54.017: D/Retrofit(3595):   at android.os.AsyncTask$2.call(AsyncTask.java:288)
11-17 16:01:54.017: D/Retrofit(3595):   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-17 16:01:54.017: D/Retrofit(3595):   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
11-17 16:01:54.017: D/Retrofit(3595):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-17 16:01:54.017: D/Retrofit(3595):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
11-17 16:01:54.017: D/Retrofit(3595):   at java.lang.Thread.run(Thread.java:841)
11-17 16:01:54.017: D/Retrofit(3595): ---- END ERROR
谷歌没有帮助我。如果你帮我解决这个问题真的很棒。感谢。

2 个答案:

答案 0 :(得分:1)

看起来像OkHtttp或您的网络服务器的SPDY或HTTP / 2实现中的错误。升级到OkHttp / 2.1。如果没有解决问题,请在OkHttp的问题跟踪器&包括导致你悲痛的服务器的主机名。

答案 1 :(得分:0)

我通过限制请求使用HTTP 1解决了类似的问题,请参阅:

OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setProtocols(Arrays.asList(Protocol.HTTP_1_1));