代码
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