Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing HttpClient warning "Invalid expires attribute" using fluent API

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 

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.

like image 826
The Coding Monk Avatar asked Apr 07 '16 10:04

The Coding Monk


2 Answers

The default HttpClient has difficulty understanding the latest RFC-compliant headers.

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(); 
like image 126
rustyx Avatar answered Sep 18 '22 03:09

rustyx


If you want to use HttpClientBuilder you can use the following sytax:

        HttpClient httpClient = HttpClientBuilder.create()             .setDefaultRequestConfig(RequestConfig.custom()                     .setCookieSpec(CookieSpecs.STANDARD).build()).build(); 
like image 33
hnaderi Avatar answered Sep 18 '22 03:09

hnaderi