如何用HttpClient来操作Cookie我的代码是这样写的: public static void main(String[] args) throws IOException
{
HttpClient client = new HttpClient();
// Set Cookie
client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
HttpState initialState = new HttpState();
Cookie cookie = new Cookie();
cookie.setDomain("group.bj.chinamobile.com");
cookie.setPath("/");
cookie.setName("JSESSIONID");
cookie.setValue("0000_jiLQsJSN3bm1gh50AUoZgY:11e205r4h");
initialState.addCookie(cookie);
client.setState(initialState);
// End
client.getHostConfiguration().setHost("group.bj.chinamobile.com", 80,
"http");
HttpMethod method = getPostMethod(); // 使用 POST 方式提交数据
client.executeMethod(method); // 打印服务器返回的状态
System.out.println(method.getStatusLine()); // 打印结果页面
String response = new String(method.getResponseBodyAsString().getBytes(
"8859_1"));
// 打印返回的信息
System.out.println(response);
method.releaseConnection();
} private static HttpMethod getPostMethod()
{
PostMethod post = new PostMethod("/edsmp/LinkmanSave.do");
NameValuePair name = new NameValuePair("name", "Sotier_Yan");
NameValuePair mphone = new NameValuePair("mphone", "13566667777");
NameValuePair agroupid = new NameValuePair("agroupid", "22508551");
post.setRequestBody(new NameValuePair[]
{ name, mphone, agroupid });
return post;
}
------------这样写有一个问题,当我在浏览器退出以后,操作就不能成功了,也就是说 JSESSIONID 失效以后 就不行了
请问该如何解决?
用户名、密码 什么的怎么设置到cookie里?
{
HttpClient client = new HttpClient();
// Set Cookie
client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
HttpState initialState = new HttpState();
Cookie cookie = new Cookie();
cookie.setDomain("group.bj.chinamobile.com");
cookie.setPath("/");
cookie.setName("JSESSIONID");
cookie.setValue("0000_jiLQsJSN3bm1gh50AUoZgY:11e205r4h");
initialState.addCookie(cookie);
client.setState(initialState);
// End
client.getHostConfiguration().setHost("group.bj.chinamobile.com", 80,
"http");
HttpMethod method = getPostMethod(); // 使用 POST 方式提交数据
client.executeMethod(method); // 打印服务器返回的状态
System.out.println(method.getStatusLine()); // 打印结果页面
String response = new String(method.getResponseBodyAsString().getBytes(
"8859_1"));
// 打印返回的信息
System.out.println(response);
method.releaseConnection();
} private static HttpMethod getPostMethod()
{
PostMethod post = new PostMethod("/edsmp/LinkmanSave.do");
NameValuePair name = new NameValuePair("name", "Sotier_Yan");
NameValuePair mphone = new NameValuePair("mphone", "13566667777");
NameValuePair agroupid = new NameValuePair("agroupid", "22508551");
post.setRequestBody(new NameValuePair[]
{ name, mphone, agroupid });
return post;
}
------------这样写有一个问题,当我在浏览器退出以后,操作就不能成功了,也就是说 JSESSIONID 失效以后 就不行了
请问该如何解决?
用户名、密码 什么的怎么设置到cookie里?
解决方案 »
- try....catch...finally
- 请教PreparedStatement问题,求各位大狭,关注下帮个忙。
- 新手请教:i is not public in newPackage.Class1; cannot be accessed 谢谢
- 高分请求解决iText中文问题
- 如何在Console模式下输入一个数字给变量
- 高分紧急求问怎么能够让在两台机器上的对应文件夹里的文件能保持一致
- 求点拨一个Socket通信程序的调试.
- 环境变量是干什么用的?
- 在java中“==”与equals有何区别,如何区分使用,最好有例子
- 请教一道JAVA题目
- 关于泛型继承的问题<E>
- JPopupMenu实现右击显示三级联动菜单怎么样实现?
楼主【sotier】截止到2008-07-21 14:24:08的历史汇总数据(不包括此帖):
发帖的总数量:27 发帖的总分数:460 每贴平均分数:17
回帖的总数量:29 得分贴总数量:4 回帖的得分率:13%
结贴的总数量:26 结贴的总分数:410
无满意结贴数:7 无满意结贴分:160
未结的帖子数:1 未结的总分数:50
结贴的百分比:96.30 % 结分的百分比:89.13 %
无满意结贴率:26.92 % 无满意结分率:39.02 %
值得尊敬
中这个cookies提交就可以了吗
true
group.bj.chinamobile.com/edsmp/
1088
4128410368
30017992
2106649168
29944567
*
----------
我是要用 登录后的cookie 来解决登陆的问题,请问程序该如何写啊?
我是要用 登录后的cookie 来解决登陆的问题,请问程序该如何写啊?