在android中做在线升级程序,在http请求数据时,出现如下错误:

java.net.SocketTimeoutException: Transport endpoint is not connected

我的解决方法是:将xxx.openConnection()改为如下代码:

HttpURLConnection conn = null;
    String host = android.net.Proxy.getDefaultHost();
    if (host != null) {
    int port = android.net.Proxy.getDefaultPort();
    SocketAddress vAddress = new InetSocketAddress(host, port);
    java.net.Proxy vProxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, vAddress);
    conn = (HttpURLConnection) downUrl.openConnection(vProxy);
    } else {
    conn = (HttpURLConnection) downUrl.openConnection();
    }