这是我的代码,我想打印cookie的消息:
PostMethod post = new PostMethod("http://www.zhihu.com/login");
if ((statusCode == HttpStatus.SC_MOVED_TEMPORARILY)
|| (statusCode == HttpStatus.SC_MOVED_PERMANENTLY)
|| (statusCode == HttpStatus.SC_SEE_OTHER)
|| (statusCode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
for (Header header : post.getResponseHeaders()) {
System.out.println(header.getName() + "----"
+ header.getValue());
}
System.out.println("header print");
}
System.out.println(post.getRequestHeader("Set-Cookie"));
打印标题时效果很好,但可以打印Cookie标题。
这是印刷信息:
Location----/
Pragma----no-cache
Cache-Control----private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0
Set-Cookie----q_c; Domain=; expires=Sun, 25 Jun 2017 ; Path=/
Set-Cookie----q_c0="NTA5NWRkYTJiNmU0OGZiZDU1MjE2YmZiYjEwMzBiOGF8UzBPWXFyckpacHpQNDJ5eQ==";Domain=; httponly; Path=/
Set-Cookie----c_c=; Domain=; expires=Wed, 26 Jun GMT; Path=/
Set-Cookie----r_i=; Domain=; expires=Wed, 26 Jun GMT; Path=/
Set-Cookie----sinaid=; Domain=; expires=Wed, 26 Jun GMT; Path=/
header print
null
答案 0 :(得分:0)
Cookie的HTTP请求标头字段为Cookie
,而不是Set-Cookie
,用于HTTP响应。