问题描述
我正在使用HttpClient的流畅API发出GET请求:
I'm using the fluent API of HttpClient to make a GET request:
String jsonResult = Request.Get(requestUrl)
.connectTimeout(2000)
.socketTimeout(2000)
.execute().returnContent().asString();
但是对于每个请求,我都会收到以下警告:
But for each request I get the following warning:
apr 07, 2016 12:26:46 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "Set-Cookie: WMF-Last-Access=07-Apr-2016;Path=/;HttpOnly;Expires=Mon, 09 May 2016 00:00:00 GMT". Invalid 'expires' attribute: Mon, 09 May 2016 00:00:00 GMT
我该如何解决并继续使用流畅的界面?理想情况下,我想要一种适当的方法来修复它,但是由于我并不真正在意用例中的cookie,因此欢迎任何允许我停止显示警告的解决方案(除了重定向stderr,因为我需要那个)
How can I fix this and keep using the fluent interface? Ideally I'd want a proper way to fix it, but since I don't really care about the cookies in my use case any solution that just allows me to stop displaying the warnings (besides redirecting stderr, cause I need that) is welcome.
推荐答案
默认HttpClient难以理解最新的RFC兼容标头。
The default HttpClient has difficulty understanding the latest RFC-compliant headers.
不是隐藏警告,而是切换到这样的标准cookie规范(HttpClient 4.4 +):
Instead of hiding the warning, just switch to a standard cookie spec like this (HttpClient 4.4+):
HttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD).build())
.build();
这篇关于修复HttpClient警告“无效的过期属性”;使用流利的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!