android https发布 - 异常

时间:2011-10-11 09:43:31

标签: android sockets

我开发了一个应用程序,它将使用https将数据发布到服务器。代码在设备上运行良好,现在我突然得到 java.net.SocketException:操作在少数设备中超时

以下是我的代码。

public void connectMe() {
    httpClient = new DefaultHttpClient();
    HttpConnectionParams
            .setConnectionTimeout(httpClient.getParams(), 25000);
    HttpConnectionParams.setSoTimeout(httpClient.getParams(), 25000);
    try {
        HttpResponse response = null;
        switch (method) {
        case GET:
            response = httpClient.execute(new HttpGet(url));
            break;
        case POST:
            try {
                HttpPost httpPost = new HttpPost(url);
                UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(
                        params, HTTP.UTF_8);
                httpPost.setEntity(p_entity);

                response = httpClient.execute(httpPost);

            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
            }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

以下是logcat信息

W/System.err( 3593): java.net.SocketException: The operation timed out

W/System.err( 3593):    at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)

W/System.err( 3593):    at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocket(OSNetworkSystem.java:130)

W/System.err( 3593):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:246)

W/System.err( 3593):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)

W/System.err( 3593):    at java.net.Socket.connect(Socket.java:1074)

W/System.err( 3593):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)

W/System.err( 3593):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:153)

W/System.err( 3593):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)

W/System.err( 3593):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)

W/System.err( 3593):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)

W/System.err( 3593):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)

W/System.err( 3593):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)

W/System.err( 3593):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

W/System.err( 3593):    at com.envision.utils.MyHttpConnection.connectMe(MyHttpConnection.java:128)

我卸载并重新安装了应用程序,没有工作得到相同的异常。但在进行工厂数据重置后,上面的代码可以在同一个移动和同一网络中工作。

任何人都可以请我解释一下发生了什么......?我很困惑..

感谢。

1 个答案:

答案 0 :(得分:0)

这看起来像是临时网络问题。您也可以尝试进入飞行模式并恢复正常再次测试。