最近在使用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.
6265, section 4 intended for interoperability with existing servers that do not conform to the well
behaved profile.
by Netscape Communications. It should be avoided unless absolutely necessary for compatibility
with legacy code.
specification defined by RFC 2965. Please do not use in new applications.--->已废弃
specification defined by RFC 2109. Please do not use in new applications--->已废弃
older versions of browser applications such as Microsoft Internet Explorer and Mozilla FireFox.
Please do not use in new applications.--->已废弃
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将会被忽略