【问题标题】:java getRequesetHeader("set-Cookie") get null why?java getRequesetHeader("set-Cookie") 得到 null 为什么?
【发布时间】:2014-06-26 21:37:29
【问题描述】:

这是我的代码,我想打印 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"));

打印header时效果很好,但是可以打印cookie的header。

这是打印出来的信息:

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

【问题讨论】:

    标签: java http cookies


    【解决方案1】:

    cookie 的 HTTP 请求标头字段是 Cookie,而不是用于 HTTP 响应的 Set-Cookie

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 2015-12-13
      • 2015-03-31
      • 1970-01-01
      • 2018-08-10
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多