我最近使用了httpclient 4.3,我知道api已经改变了,但是如果不设置超时阈值(连接或套接字或连接管理器),它可以工作,这意味着没有无限循环查询,并且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;
}
...