HttpClient4.5.3 警告:Invalid cookie header 的问题解决

最近在使用HttpClient发送请求时发现经常报Invalid cookie header警告

org.apache.http.client.protocol.ResponseProcessCookies processCookies
警告: Invalid cookie header: "Set-Cookie: q_c1=484d1c0f82e1461790775962c93f1875|1516253307000|1516253307000; path=/; expires=Sun, 17 Jan 2021 05:28:27 GMT; domain=zhihu.com; httponly". Invalid 'expires' attribute: Sun, 17 Jan 2021 05:28:27 GMT

这时候需要修改请求中的cookie策略(CookieSpecs)

RequestConfig defaultConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
getMethod.setConfig(defaultConfig);
这样即可以解决


附带几种CookieSpecs的详解

HttpClient附带了几个CookieSpec的实现

Standard strict:State management policy compliant with the syntax and semantics of the wellbehaved profile defined by RFC 6265, section 4.


Standard:State management policy compliant with a more relaxed profile defined by RFC
6265, section 4 intended for interoperability with existing servers that do not conform to the well

behaved profile.


Netscape draft (obsolete):This policy conforms to the original draft specification published
by Netscape Communications. It should be avoided unless absolutely necessary for compatibility

with legacy code.


RFC 2965 (obsolete):State management policy compliant with the obsolete state management

specification defined by RFC 2965. Please do not use in new applications.--->已废弃


RFC 2109 (obsolete):State management policy compliant with the obsolete state management

specification defined by RFC 2109. Please do not use in new applications--->已废弃


Browser compatibility (obsolete):This policy strives to closely mimic the (mis)behavior of
older versions of browser applications such as Microsoft Internet Explorer and Mozilla FireFox.

Please do not use in new applications.--->已废弃


Default:Default cookie policy is a synthetic policy that picks up either RFC 2965, RFC 2109
or Netscape draft compliant implementation based on properties of cookies sent with the HTTP
response (such as version attribute, now obsolete). This policy will be deprecated in favor of the
standard (RFC 6265 compliant) implementation in the next minor release of HttpClient.


Ignore cookies:所有的cookie将会被忽略


  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值