试试这个
public class MyAsync extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... arg0) {
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient client=new DefaultHttpClient(httpParameters);
HttpGet get=new HttpGet(arg0[0]);
try {
HttpResponse response=client.execute(get);
HttpEntity ent=response.getEntity();
String res=EntityUtils.toString(ent);
Log.d("Nzm", res);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}