gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:44:25 25 4
gpt4 key购买 nike

大家中午好!

我正在使用 Retrofit 在我的应用程序中进行网络调用。该应用程序确实运行良好,速度很快。感谢精彩的图书馆。但是,它仅适用于 wi-fi。如果我在 3G 网络中运行该应用程序,则会抛出错误。 流已重置:PROTOCOL_ERROR,同时在 3G 网络中使用 Retrofit

我已将此 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

Google 没有帮助我。如果你能帮我解决这个问题就太好了。谢谢。

最佳答案

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

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

关于android - 在 3G 网络中使用 Retrofit 时流被重置为 : PROTOCOL_ERROR,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com