HTMLUnit rejects cookie

I am trying to connect to some website using the HTMLUnit library. The problem is that my HTMLUnit client does not accept cookies from this site with the following message:

WARNING: Cookie rejected: "[version: 0] [name: remixchk] [value: 5] [domain: .vkontakte.ru] [path: /] [expiration: Tue Feb 21 08:53:46 MSK 2012]". Illegal domain attribute "vkontakte.ru". Domain of origin: "login.vk.com"

This is due to the fact that the login form is sent to an address different from the site address.

I need to change the cookie policy in my client. I know that I have to rewrite the method getCookiesin the class CookieManager. I did this in a subclass CookieManagerand then changed CookieManagermy client this way:

webClient.setCookieManager(new mySubclassedCookieManager());

But it does not change anything. Moreover, when a cookie is rejected, the getCookies method never starts.

Where did I go wrong? How to force HTMLUnit to accept this cookie?

+3
source share
1 answer

You must not change the client: you must change the design of your application. HTMLUnit does what any real browser does in this case: reject the cookie. A website cannot set cookies for another domain for security (and privacy) reasons.

+1
source

Source: https://habr.com/ru/post/1795176/


All Articles