问题描述
我想知道是否存在已知的在Android问题HttpURLConnection类和POST请求。我们正在经历的间歇 EOFExceptions来自Android客户端使POST请求时。重试相同的请求最终会工作。下面是一个示例堆栈跟踪:
I would like to know if there are known issues on Android with HttpUrlConnection and POST requests. We are experiencing intermittent EOFExceptions when making POST requests from an Android client. Retrying the same request will eventually work. Here is a sample stack trace:
java.io.EOFException
at libcore.io.Streams.readAsciiLine(Streams.java:203)
at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:579)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
有很多类似的错误报告和职位堆栈溢出,但我不明白,如果真的有问题,如果是这样,什么版本的Android受到影响,有什么建议修复/解决办法是。
There are many similar bug reports and posts to stack overflow but I cannot understand if there really is an issue and if so, what versions of Android are affected and what the proposed fix/work around is.
下面是一些类似的报告,我指的是:
Here are some of the similar reports I am referring to:
- 的Android HttpsUrlConnection EOFException类
- Android HttpURLConnection的抛出EOFException类
- EOFException和FileNotFoundException异常中的HttpURLConnection的getInputStream()
- <一个href="https://$c$c.google.com/p/google-http-java-client/issues/detail?id=213">https://$c$c.google.com/p/google-http-java-client/issues/detail?id=213
- <一个href="https://$c$c.google.com/p/android/issues/detail?id=29509">https://$c$c.google.com/p/android/issues/detail?id=29509
- <一个href="https://$c$c.google.com/p/google-http-java-client/issues/detail?id=230">https://$c$c.google.com/p/google-http-java-client/issues/detail?id=230
- <一个href="https://$c$c.google.com/p/android/issues/detail?id=41576">https://$c$c.google.com/p/android/issues/detail?id=41576
- Android HttpsUrlConnection eofexception
- Android HttpURLConnection throwing EOFException
- EOFException and FileNotFoundException in HttpURLConnection getInputStream()
- https://code.google.com/p/google-http-java-client/issues/detail?id=213
- https://code.google.com/p/android/issues/detail?id=29509
- https://code.google.com/p/google-http-java-client/issues/detail?id=230
- https://code.google.com/p/android/issues/detail?id=41576
下面是一个潜在的Android框架修复
Here is a potential Android framework fix
- https://android.googlesource.com/platform/libcore/+/19aa40c81c48ff98ccc7272f2a3c41479b806376
我知道有一个问题,在连接池毒死连接在pre-升级Froyo,但这些问题正在发生新的ICS +设备专用。如果有在更高版本的设备一个问题,我希望一些问题的官方Android文档。
I do know there was an issue with poisoned connections in the connection pool in pre-Froyo but these issues are occurring on new ICS+ devices exclusively. If there were a problem on later devices I would expect some kind of official Android documentation of the issue.
推荐答案
我们的结论是,有一个在Android平台的问题。我们的解决方法是赶上EOFException类和重试次数的要求N多。下面是伪code:
Our conclusion is that there is an issue in the Android platform. Our workaround was to catch the EOFException and retry the request N number of times. Below is the pseudo code:
private static final int MAX_RETRIES = 3;
private ResponseType fetchResult(RequestType request) {
return fetchResult(request, 0);
}
private ResponseType fetchResult(RequestType request, int reentryCount) {
try {
// attempt to execute request
} catch (EOFException e) {
if (reentryCount < MAX_RETRIES) {
fetchResult(request, reentryCount + 1);
}
}
// continue processing response
}
这篇关于Android的HttpURLConnection的EOFException类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!