1,需要同时使用commons-codec-1.3.jar
2,处理header
a.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%
response.addHeader("location","beijing");
%>
3,
HttpClient client = new HttpClient();
HeadMethod headMethod = new HeadMethod(
"http://localhost:8080/Test/jsp/a.jsp");
client.executeMethod(headMethod);
Header[] headers = headMethod.getResponseHeaders();
System.out.println(headers.length);
for (int i = 0; i < headers.length; i++) {
out.println(headers[i] + " <br>");
}
headMethod.releaseConnection();
4,
httpclient默认使用ISO-8859-1读取http响应的内容,如果内容中包含汉字的话就得动用丑陋的new String(str.getBytes("ISO-8859-1"),"GBK");语句了。
解决办法
HttpClient client = new HttpClient();
client.getParams().setParameter(
HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK");
5,设置 Http 连接超时为2秒
httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(2000);
9,很好的帖子
http://laohuang.javaeye.com/blog/55613
http://www.blogjava.net/Alpha/archive/2007/01/22/95216.html
http://www.cnjm.net/tech/article1155.html
15,资源:
http://hi.baidu.com/toad24/blog/item/6d4e734e4ac2d00bb3de05d3.html
AD:http://dev2dev.bea.com.cn/techdoc/20060621823.html#_Toc131329166
http认证:http://dev.csdn.net/author/Jason009/769317e872024d0f8a2710141384ba47.html
http://www.javaeye.com/topic/84996
超时http://lkf0217.javaeye.com/blog/601104
超时http://skyful.javaeye.com/blog/518735