Android的HttpsUrlConnection EOFException类 [英] Android HttpsUrlConnection eofexception

查看:305
本文介绍了Android的HttpsUrlConnection EOFException类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我HttpsURLConnection将抛出的EOFException当我尝试读取任何输入。在code适用于某些网络电话,但没有别人。如果我试图从连接读取任何东西时,出现上述错误。

I have a problem where my HttpsURLConnection will throw an EOFException when i try to read any input. The code works for some network calls, but fails on others. If i try and read anything from the connection, it fails with the aforementioned error.

例如:

urlConnect.getResponseCode() // will throw error
urlConnect.getResponseMessage() // will throw error
BufferedInputStream in = new BufferedInputStream(urlConnect.getInputStream()); //will throw error

下面是每个堆栈跟踪:

GETRESPONSE:

getResponse:

03-14 09:49:18.547: W/System.err(6270): java.io.EOFException
03-14 09:49:18.547: W/System.err(6270):     at libcore.io.Streams.readAsciiLine(Streams.java:203)
03-14 09:49:18.547: W/System.err(6270):     at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573)
03-14 09:49:18.547: W/System.err(6270):     at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821)
03-14 09:49:18.547: W/System.err(6270):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
03-14 09:49:18.547: W/System.err(6270):     at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495)
03-14 09:49:18.547: W/System.err(6270):     at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)

的BufferedInputStream:

BufferedInputStream:

03-14 09:39:14.077: W/System.err(5935): java.io.EOFException
03-14 09:39:14.077: W/System.err(5935):     at libcore.io.Streams.readAsciiLine(Streams.java:203)
03-14 09:39:14.077: W/System.err(5935):     at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573)
03-14 09:39:14.077: W/System.err(5935):     at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821)
03-14 09:39:14.077: W/System.err(5935):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
03-14 09:50:46.547: W/System.err(6476):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
03-14 09:50:46.547: W/System.err(6476):     at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)

感谢您的帮助,

里克

修改 我发现我的答案是:

EDIT I found my answer:

这是不是一个有据可查的答案。它出现在一些较新版本的Andr​​oid中,有一个与回收URL连接的错误。为了解决这个问题(虽然可能有一些性能问题),我还需要增加:

This was not a well documented answer. It appears in some of the newer versions of android, there is a bug with recycled url connections. To fix this (although there may be some performance issues), I needed to add:

if (Build.VERSION.SDK != null
&& Build.VERSION.SDK_INT > 13) {
urlConnect.setRequestProperty("Connection", "close");
}

谢谢!

里克

推荐答案

有人要求我回答的编辑我自己的问题,而不是。因此,这里又是答案。

Someone requested I answer my own question instead of editing. So here is the answer again.

这是不是一个有据可查的答案。它出现在一些较新版本的Andr​​oid中,有一个与回收URL连接的错误。为了解决这个问题(虽然可能有一些性能问题),我还需要增加:

This was not a well documented answer. It appears in some of the newer versions of android, there is a bug with recycled url connections. To fix this (although there may be some performance issues), I needed to add:

if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) {
    urlConnect.setRequestProperty("Connection", "close");
}

这篇关于Android的HttpsUrlConnection EOFException类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆