在论坛上看到,有人用httpParams中的超时。我也这样试试 但是没有反应 请教各位究竟是错在哪里了,我的代码如下:
public final static InputStream getStream(String args) {
InputStream stream = null;
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
HttpClient client = new DefaultHttpClient(httpParams);
HttpGet get = new HttpGet(args);
try {
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
stream = entity.getContent();
}
return stream;
} catch (Exception e) {
e.printStackTrace();
return stream;
}
}
public final static InputStream getStream(String args) {
InputStream stream = null;
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
HttpClient client = new DefaultHttpClient(httpParams);
HttpGet get = new HttpGet(args);
try {
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
stream = entity.getContent();
}
return stream;
} catch (Exception e) {
e.printStackTrace();
return stream;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货