Apache HttpClient的简单用法
// Apache HttpClient包可以通过纯java来解析http协议,直接进行请求然后之后对结果进行处理// 创建HttpClient实例
HttpClient client = new HttpClient();
// 设置超时时间
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
// HttpClient方法
HttpMethod method = new GetMethod("http://service.qq.com/XML/hittop.xml");
// 如有参数使用如下函数进行添加
// method.setQueryString()
// 执行方法
client.executeMethod(method);
// 将获取的结果作为字符串进行处理
String responseBody = method.getResponseBodyAsString();
// 关闭链接
method.releaseConnection();
页:
[1]