HttpConnectionParams.setConnectionTimeout HTTP设置超时连接无效
private void TestHttpConnect() throws ClientProtocolException, IOException{
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 5*1000);
HttpConnectionParams.setSoTimeout(httpParams, 5*1000);
HttpResponse httpResponse;
HttpGet httpGet = new HttpGet("http://www.baidu.com");
HttpClient httpClient = new DefaultHttpClient(httpParams);
httpGet.setParams(httpParams);
httpResponse = httpClient.execute(httpGet);
if(httpResponse.getStatusLine().getStatusCode() == 200)
{
Log.e("tag", "Got address..");
}
else
{
Log.e("tag", " Connection Timeout");
}
}
如上述代码中,我设置了连接超时5秒,为什么在我的android手机没有网络的时候,等待超时一直等待,大约等了90秒,为什么??为什么无法设置超时 --------------------编程问答-------------------- 答案还是要靠自己去找。
补充:移动开发 , Android