HttpClient WARNING: Cookie rejected: Illegal domain attribute
Before httpclient
4.3, this answer in the same page is cool.
But since httpclient
4.3, API seems changed a lot, following code would work:
RequestConfig customizedRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
HttpClientBuilder customizedClientBuilder = HttpClients.custom().setDefaultRequestConfig(customizedRequestConfig);
CloseableHttpClient client = customizedClientBuilder.build(); // customized client,
You can't "fix" it. The site is trying to set a cookie it's not allowed to set and the apache client library you're using is telling you about it.
It's trying to set a cookie for mcore.com
when the domain is goklik.co.id
Maybe it's too late, but I had the same problem and I've found something that helped me work it out, just set the Cookie Policy to Browser Compability:
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.BROWSER_COMPATIBILITY);
Here are the possible values:
The cookie policy provides corresponding cookie management interfrace for a given type or version of cookie.
RFC 2109 specification is used per default. Other supported specification can be chosen when appropriate or set default when desired
The following specifications are provided:
BROWSER_COMPATIBILITY
: compatible with the common cookie management practices (even if they are not 100% standards compliant)NETSCAPE
: Netscape cookie draft compliantRFC_2109
: RFC2109 compliant (default)IGNORE_COOKIES
: do not automcatically process cookies
I am using http client 4.5.2 and this is set cookie spec to easy solved my problem. The example of how instantiate client:
httpClient = HttpClients.custom()
.setDefaultRequestConfig(RequestConfig.custom()
// Waiting for a connection from connection manager
.setConnectionRequestTimeout(10000)
// Waiting for connection to establish
.setConnectTimeout(5000)
.setExpectContinueEnabled(false)
// Waiting for data
.setSocketTimeout(5000)
.setCookieSpec("easy")
.build())
.setMaxConnPerRoute(20)
.setMaxConnTotal(100)
.build();