java.net.SocketTimeoutException: Read timed out 的解决办法 android平台 腾讯微博开发

刚接手腾讯微博,做了个小DEMO。公司网络有代理。发照片时一半左右发送失败,错误信息如下

W/System.err(31723): java.net.SocketTimeoutException: Read timed out
W/System.err(31723):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
W/System.err(31723):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:675)
W/System.err(31723):     at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
W/System.err(31723):     at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
W/System.err(31723):     at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
W/System.err(31723):     at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
W/System.err(31723):     at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
W/System.err(31723):     at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
W/System.err(31723):     at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
W/System.err(31723):     at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
W/System.err(31723):     at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
W/System.err(31723):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
W/System.err(31723):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err(31723):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err(31723):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err(31723):     at com.tencent.weibo.utils.QHttpClient.httpPostWithFile(QHttpClient.java:219)
W/System.err(31723):     at com.tencent.weibo.oauthv2.OAuthV2Request.postFile(OAuthV2Request.java:99)
W/System.err(31723):     at com.tencent.weibo.api.TAPI.addPic(TAPI.java:310)
W/System.err(31723):     at com.tencent.weibo.api.TAPI.addPic(TAPI.java:276)
W/System.err(31723):     at com.android.tencent.MainActivity$3.run(MainActivity.java:160)
I/QHttpClient.class(31723): QHttpClient httpPostWithFile [3] responseData = null

报错位置在QHttpClient.java    line 219

try {
            HttpResponse response=httpClient.execute(httpPost);
            Log.i(TAG, "QHttpClient httpPostWithFile [2] StatusLine = "+response.getStatusLine());
            responseData =EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
          httpPost.abort();
        }

解决办法:把socket的超时时间设置的长一些。

把代码改为:

try {
        	httpClient.getParams().setParameter("http.socket.timeout", new Integer(30000));
            HttpResponse response=httpClient.execute(httpPost);
            Log.i(TAG, "QHttpClient httpPostWithFile [2] StatusLine = "+response.getStatusLine());
            responseData =EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
          httpPost.abort();
        }

我把socket的超时时间设置为了30000.非常长。不知道会不会有其他的问题存在,但是亲测,发送了11张照片全部成功。


你可能感兴趣的:(java.net.SocketTimeoutException: Read timed out 的解决办法 android平台 腾讯微博开发)