============ Problem Description ============
HttpURLConnection conn = (httpurlconnection) u.openconnection ();
Conn.setdoinput (TRUE);
Conn.setdooutput (TRUE);
Conn.setconnecttimeout (10000);
Conn.setrequestmethod ("POST");
Conn.setrequestproperty ("Response-type", "JSON");//Add message headers
Conn.connect ();
DataOutputStream out = new DataOutputStream (Conn.getoutputstream ());
StringBuilder data = new StringBuilder ("");
for (int i=0;i<keys.length;i++) {
if (values[i]! = NULL &&! "". Equals (Values[i])) {
Tblog.info ("Key:" +keys[i]+ "values:" +values[i]);
Data.append (Keys[i]). Append ("="). Append (Urlencoder.encode (values[i), "UTF-8"). Append ("&");
}
}
if (Data.length () >0) {
data = Data.deletecharat (Data.length ()-1);
}
Tblog.info ("Data:" +data.tostring ());
Out.write (Data.tostring (). GetBytes ());
Out.flush ();
Out.close ();
if (Conn.getresponsecode () ==200) {
InputStream is = Conn.getinputstream ();
Return convertstreamtostring (IS);
}
============ Solution 1============
Well, is this a timeout? I'm not even supposed to.
You enter 180.186.31.33:8080 in the browser to try to open no
============ Solution 2============
/**
* Connection Timeout time
*/
Public final static int connect_timeout = 10000;
/**
* Read Timeout time
*/
Public final static int read_timeout = 30000;
Connmanagerparams.setmaxtotalconnections (Httpparams,
Max_total_connections);
Set the maximum wait time to get a connection
Httpconnectionparams.setconnectiontimeout (Httpparams,
Connect_timeout);
Httpconnectionparams.setsotimeout (Httpparams, read_timeout);
Set these three parameters to uppercase try
Android HttpURLConnection or httpclient always timeout, the server is OK, but the network is OK, the browser can surf the internet