Wednesday, March 5, 2014

android httpurlconnection or httpclient always timeout, the server is normal, but normal network, Internet browser


HttpURLConnection conn = (HttpURLConnection) u.openConnection ();
conn.setDoInput (true);
conn.setDoOutput (true);
conn.setConnectTimeout (10000);
conn.setRequestMethod ("POST");
conn.setRequestProperty ("Response-Type", "json") ;/ / add header

conn.connect ();
DataOutputStream out = new DataOutputStream (conn.getOutputStream ());
StringBuilder data = new StringBuilder ("");
for (int i = 0; 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);
}<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
08-21 14:35:37.919: W / System.err (6085): java.net.SocketTimeoutException: failed to connect to / 180.186.31.33 (port 8080) after 10000ms
08-21 14:35:37.919: W / System.err (6085): at libcore.io.IoBridge.connectErrno (IoBridge.java: 159)
08-21 14:35:37.929: W / System.err (6085): at libcore.io.IoBridge.connect (IoBridge.java: 112)
08-21 14:35:37.929: W / System.err (6085): at java.net.PlainSocketImpl.connect (PlainSocketImpl.java: 192)
08-21 14:35:37.929: W / System.err (6085): at java.net.PlainSocketImpl.connect (PlainSocketImpl.java: 460)

Reply:
Great God seeking answers Yeah
Reply:
This is the amount of overtime? Rom it should be
You enter in your browser 180.186.31.33:8080 not try to open
Reply:
Will not add permissions ah
Reply:
/ **
* Connect timeout
* /
public final static int CONNECT_TIMEOUT = 10000;
/ **
* Read timeout
* /
public final static int READ_TIMEOUT = 30000;

ConnManagerParams.setMaxTotalConnections (httpParams,
MAX_TOTAL_CONNECTIONS);
/ / Set the maximum waiting time to get a connection
HttpConnectionParams.setConnectionTimeout (httpParams,
CONNECT_TIMEOUT);
HttpConnectionParams.setSoTimeout (httpParams, READ_TIMEOUT);

Try these three parameters in uppercase
Reply:
ConnManagerParams.setMaxTotalConnections (httpParams,
MAX_TOTAL_CONNECTIONS); This is not set up, wrong
Reply:
references, 5th Floor weekendboyxw reply:
/ **
* Connect timeout
* /
public final static int CONNECT_TIMEOUT = 10000;
/ **
* Read timeout
* /
public final static int READ_TIMEOUT = 30000;

ConnManagerParams.setMaxTotalConnections (httpParams,
MAX_TOTAL_CONNECTIONS);
/ / Set the maximum waiting time to get a connection
HttpConnectionParams.setConnectionTimeout (httpParams,
CONNECT_TIMEOUT);
HttpConnectionParams.setSoTimeout (httpParams, READ_TIMEOUT);

Try these three parameters in uppercase
I found a server problem. Code everything is normal, that is not responding,
Reply:
I have encountered this problem, often times out, the same background, ios can access, android client can not be accessed, the browser opens the interface can also be accessed.
Reply:
May I ask how to solve ah
Reply:
reference to the 8th floor guoshijie1990 reply:
I have encountered this problem, often times out, the same background, ios can access, android client will not be able to access The browser opens the interface can also be accessed.


I still do not solve this problem, in the first open connection fails, you must periodically reconnect to succeed, or kill the application process, to re-open the connection just fine. Is httpclient cache problem?
Reply:
ask someone to solve it. . . . I am also the case IOS Android side code pages can be no problem ah normally accessible but often time out. .

No comments:

Post a Comment