【发布时间】:2016-01-02 15:38:14
【问题描述】:
我最近用的是httpclient 4.3,知道api改了,但是如果不设置超时阈值(conenction or socket or conenctionmanager),它可以工作,也就是说没有无限循环查询,method.getResponseBodyAsString()会返回一个空字符串,但是在文档中说超时的默认参数设置是无限的,那么它是如何工作的呢?
public class ContentModelUtils {
private static HttpClient client = new HttpClient();
...
public static String fetchPlainHttpResult(String id, Map<String, String> result, String getUrl)
throws HttpException, IOException {
method = new GetMethod(fetchPlainUrl(id, result, getUrl));
//client.getParams().setParameter("http.socket.timeout",1000);
//client.getParams().setParameter("http.connection.timeout",1000);
//client.getParams().setParameter("http.connection-manager.timeout",10000L);
client.executeMethod(method);
if (method.getStatusCode() != 200) {
return null;
}
String outputValue = new String(method.getResponseBodyAsString());
return outputValue;
}
...
【问题讨论】:
标签: java httpclient