2014-06-26 67 views
0

這是我的代碼,我婉打印餅乾的消息:java getRequesetHeader(「set-Cookie」)get null爲什麼?

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")); 

打印頭時,它工作得很好,但可以打印出來作爲餅乾頭。

這是印刷的信息:

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

HTTP請求報頭字段餅乾是Cookie,不Set-Cookie,這是HTTP響應。