HttpClient WARNING: Cookie rejected: Illegal domain attribute

前端 未结 7 780
慢半拍i
慢半拍i 2020-12-09 03:36

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         


        
相关标签:
7条回答
  • 2020-12-09 03:49

    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,
    
    0 讨论(0)
  • 2020-12-09 03:53

    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

    0 讨论(0)
  • 2020-12-09 03:57

    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();
    
    0 讨论(0)
  • 2020-12-09 04:02

    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();
    
    0 讨论(0)
  • 2020-12-09 04:02

    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.

    0 讨论(0)
  • 2020-12-09 04:08

    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

    0 讨论(0)
提交回复
热议问题