gpt4 book ai didi

android - com.android.volley.NoConnectionError 暂停应用后

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:09 25 4
gpt4 key购买 nike

我正在使用 Google Volley 和 Gson 编写我的应用程序,以使用 OkHttp 作为 HTTP-Stack 与 REST 服务对话。这在大多数情况下都很好,但是当我暂停我的应用程序并返回到它时,HTTP 请求不适用于此异常:

     09-08 19:29:19.611: E/ASDF(21827): com.android.volley.NoConnectionError: java.io.EOFException
09-08 19:29:19.611: E/ASDF(21827): at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:125)
09-08 19:29:19.611: E/ASDF(21827): at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
09-08 19:29:19.611: E/ASDF(21827): Caused by: java.io.EOFException
09-08 19:29:19.611: E/ASDF(21827): at java.util.zip.GZIPInputStream.readFully(GZIPInputStream.java:206)
09-08 19:29:19.611: E/ASDF(21827): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:98)
09-08 19:29:19.611: E/ASDF(21827): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
09-08 19:29:19.611: E/ASDF(21827): at com.squareup.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:461)
09-08 19:29:19.611: E/ASDF(21827): at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:659)
09-08 19:29:19.611: E/ASDF(21827): at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:346)
09-08 19:29:19.611: E/ASDF(21827): at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:295)
09-08 19:29:19.611: E/ASDF(21827): at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:489)
09-08 19:29:19.611: E/ASDF(21827): at com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:136)
09-08 19:29:19.611: E/ASDF(21827): at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:109)
09-08 19:29:19.611: E/ASDF(21827): at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
09-08 19:29:19.611: E/ASDF(21827): ... 1 more

这是随机发生的。不是每次我暂停我的应用程序。我真的不知道从哪里开始。

最佳答案

看来这个问题是由Android本身的一个错误引起的,应该修复!?此处描述了该问题及其修复:Android issue 24672

所以将这段代码添加到我的 OkHttp URLConnection 工厂立即解决了这个问题:

  @Override protected HttpURLConnection createConnection(URL url) throws IOException {
HttpURLConnection connection = client.open(url);
// Fix for bug in Android runtime(!!!):
// https://code.google.com/p/android/issues/detail?id=24672
connection.setRequestProperty("Accept-Encoding", "");

return connection;
}

关于android - com.android.volley.NoConnectionError 暂停应用后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18686671/

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