如何用httpclient获得网页内容
小虾用httpclient模拟一个post包请求网站loginServlet获得了该网站返回的response信息
部分代码如下:
//建立连接
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod method = new PostMethod("/StarMap/loginservlet?tag=login");
//传递username和userpassword模拟post方法传参给servlet
NameValuePair name = new NameValuePair("username", "xxxxxxx");
NameValuePair pass = new NameValuePair("userpassword", "xxxxxx");
NameValuePair[] namevaluepair = { name, pass };
//返回执行连接的状态
int status = client.executeMethod(method);
//把得到的信息添加到response头中建立新的连接
Header locationHeader = method.getResponseHeader("Set-Cookie");
GetMethod method2 = new GetMethod("/StarMap/main/main.jsp");
method2.setRequestHeader(locationHeader);
client.executeMethod(method2);
String body=method2.getResponseBodyAsString();
System.out.println(body);
控制台可以打印该jsp的源代码,由于该jsp中嵌套了其他的jsp,其在加载时需要对用户登录进行判断,到这时就会出现用户非法登录的信息
请问一下我该怎样在httpclient中获得cookie并保存到本地或会话过程中有效(服务期使用的是session会话保存信息,我这边不知到存的信息)