Invalid cookie header : Unable to parse expires attribute when expires attribute is empty

后端 未结 2 1684
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 21:40

In an android application, when using DefaultHttpClient to get an URL content (executing HttpGet) I receive the following warning in logs:

W/Re         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-16 22:27

    I just got the similar warns like below

    Invalid cookie header: "Set-Cookie: A3=d=AQABBPA3c18CEOtNC3d8X1pEkCvrf2cxZRIFEgEBAQGJdF99XwAAAAAA_SMAAA&S=AQAAAiTHBvO_oaoz8tCr1A7ArCs; Expires=Wed, 29 Sep 2021 19:34:41 GMT; Max-Age=31557600; Domain=.yahoo.com; Path=/; SameSite=None; Secure; HttpOnly". Invalid 'expires' attribute: Wed, 29 Sep 2021 19:34:41 GMT
    

    My env is http client-4.5.12, the reason is that cookiesSpec need to be set.

    Way to fix (just ignore other parameters)

    requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
    
            httpclient = HttpClients.custom()
                   .setDefaultRequestConfig(requestConfig).build();
    

    Here you can change the CookieSpecs.XXX align with your condition, for most case, STANDARD is ok, details can refer latest apache doc https://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/statemgmt.html

    NOTES that the HttpClientParams (some pages mentioned before)is a deprecated class, just use RequestConfig as the replacement.

提交回复
热议问题