导航

Android网络访问超时

Posted on 2010-08-10 10:46  Enrico Zhang  阅读(2212)  评论(0编辑  收藏  举报

代码
1 HttpGet httpGet = new HttpGet(url);
2 HttpParams httpParameters = new BasicHttpParams();
3  // Set the timeout in milliseconds until a connection is established.
4  int timeoutConnection = 3000;
5 HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
6  // Set the default socket timeout (SO_TIMEOUT)
7 // in milliseconds which is the timeout for waiting for data.
8 int timeoutSocket = 5000;
9 HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
10
11 DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
12 HttpResponse response = httpClient.execute(httpGet);
13