java 设置http请求超时

public class TestHttpClientMain {

public static void main(String[] args) {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(
"http://test.com");
client.getHttpConnectionManager().getParams()
.setConnectionTimeout(3000);
client.getHttpConnectionManager().getParams().setSoTimeout(3000);
try {
int statusCode = client.executeMethod(meth(www.111cn.net)od);
System.out.println(statusCode);
byte[] responseBody = null;
responseBody = method.getResponseBody();
String result = new String(responseBody);
System.out.println(result);
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
from:http://www.111cn.net/jsp/Java/55314.htm

猜你喜欢

转载自hoochiang.iteye.com/blog/2238009