I\'m using HttpClient latest version (4.x). And right now I\'m trying to do A GET Request. I just posting a Get request.
This is my Code;
public clas
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
Here is the simplest way to suppress the warning in v4.5.x (4.5.6 right now) :
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.disableCookieManagement();
HttpClient httpClient = clientBuilder.build();
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();
Just want to improve Eric's answer, as it doesnt directly solve my scenario but changing CookieSpecs to IGNORE_COOKIES solves my problem.
RequestConfig customizedRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
HttpClientBuilder customizedClientBuilder =
HttpClients.custom().setDefaultRequestConfig(customizedRequestConfig);
CloseableHttpClient client = customizedClientBuilder.build(); // customized client,
Because in my version of HttpClient 4.5 CookieSpecs.BROWSER_COMPATIBILITY is already depreciated.
If you don't need to process cookies you can simply disable it, with org.apache.http.impl.cookie.IgnoreSpecProvider
or org.apache.http.impl.cookie.IgnoreSpec
depending on what API you use. Calling disableCookieManagement()
on HttpClientBuilder
is not enough