使用loopj AsyncHttpClient获取SocketTimeoutExceptions。

时间:2017-12-19 08:08:19

标签: android asynchttpclient

posix_spawn()

我已经实现了以下代码: -

12-19 13:28:49.902 22731-23091/com.aadi.edusuit W/System.err: java.net.SocketTimeoutException
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at java.net.PlainSocketImpl.read(PlainSocketImpl.java:484)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at java.net.PlainSocketImpl.-wrap0(PlainSocketImpl.java)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:223)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:860)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:146)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:177)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:106)
12-19 13:28:49.903 22731-23091/com.aadi.edusuit W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
12-19 13:28:49.904 22731-23091/com.aadi.edusuit W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-19 13:28:49.904 22731-23091/com.aadi.edusuit W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
12-19 13:28:49.904 22731-23091/com.aadi.edusuit W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
12-19 13:28:49.904 22731-23091/com.aadi.edusuit W/System.err:     at java.lang.Thread.run(Thread.java:818)

但上述代码仅在一个会话中有效一次;如果我在同一个会话中发出另一个请求,我会再次获得Socket超时异常。

1 个答案:

答案 0 :(得分:0)

增加你的超时时间可能是互联网太慢而无法建立连接,即试试这个

console.log(data)