How to resolve org.apache.http.conn.ConnectTimeoutException in Android?

Narasimha picture Narasimha · Feb 10, 2014 · Viewed 7.9k times · Source

I am working on service related application.

DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpParams params = httpClient.getParams();
            HttpConnectionParams.setConnectionTimeout(params, 10000000);
            HttpConnectionParams.setSoTimeout(params, 15000000);
            HttpProtocolParams.setUseExpectContinue(httpClient.getParams(),true);

            String str_Server_Host = Control_PWD_Server_Name();
            String requestEnvelope = String.format(envelope_oe);
            // HttpPost httpPost = new HttpPost(str_Server_Host);
            HttpPost httpPost = new HttpPost(str_Server_Host);
            httpPost.setHeader("SOAPAction",
                    "http://tempuri.org/updateTransportStatus");
            httpPost.setHeader("Content-Type", "text/xml;charset=utf-8");
            httpPost.setEntity(new StringEntity(requestEnvelope));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();

            line = EntityUtils.toString(httpEntity);
            String str = Html.fromHtml(line).toString();

This is the exception I am getting:

org.apache.http.conn.ConnectTimeoutException: Connect to /10.64.0.184:9092 timed out

How to resolve above exception in android? please give any suggestion or related senario.

Answer