在写这篇文章之前我做了很长时间的搜索,我做了很多测试但没有成功。
我的问题(简而言之):使用3g数据连接,每次我做一个get请求,第一次连接成功。
现在,如果设备处于待机状态几分钟,当我重复相同的获取请求时,它会立即失败,并出现我在下面报告的错误。一些评论:
- 我只在Rooted Nexus 5 (Android 4.4.2)上遇到这个问题
- 如果设备不进入待机状态,我无法重现该问题
- 如果我第三次尝试,则连接成功。
- 在 WiFi 模式下,我无法重现该问题。
- 还使用 Galaxy S3 (android 4.3) 和 Galaxy S1 进行了测试,无法重现该问题。
- 我正在使用Loopj AsyncHttpClient libray(1.4.4)的最新版本:http : //loopj.com/android-async-http/doc/com/loopj/android/http/AsyncHttpClient.html
错误详情
javax.net.ssl.SSLException: Read error: ssl=0x75cab460: I/O error during system call,
Connection reset by peer
at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:689)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:74)
at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:91)
at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Response body is null, calling onFailure(Throwable, JSONObject)
让我们看一些代码。
我有一个管理所有连接的单例类:
...
//Static istance of my httpClient
private static AsyncHttpClient client = new AsyncHttpClient();
//This is the only parameter that I'm setting for the client
client.setTimeout(30000);
...
//When i need to a get request I just use the following code.
client.get(mContext, url, params, responseHandler);
//For testing purpose, before doing any get request, I've done a clear of all requests,
//but this is not helping with my problem.
client.cancelRequests(mContext, true);
我现在迷路了:我不知道我是否缺少客户端上的一些配置参数,或者客户端是否试图重用错误的连接等等......
我是图书馆的新用户,所以我真的可能做错了什么。
我希望有一个人可以帮助我。
提前致谢。