Reputation: 1495
I am trying to connect to some website using HTMLUnit library. A problem is that my HTMLUnit client do not accepts a cookie from that site with the following message:
WARNING: Cookie rejected: "[version: 0][name: remixchk][value: 5][domain: .vkontakte.ru][path: /][expiry: Tue Feb 21 08:53:46 MSK 2012]". Illegal domain attribute "vkontakte.ru". Domain of origin: "login.vk.com"
This is because the login form is submitted to the address different from site address.
I need to change a cookie policy in my client. I know, that I should rewrite a getCookies
method in CookieManager
class. I have done this in a subclass of CookieManager
and then changed the CookieManager
of my client in this way:
webClient.setCookieManager(new mySubclassedCookieManager());
But this changes nothing. Moreover, when rejecting the cookie the getCookies method never runs.
Where I went wrong? How can I force HTMLUnit to accept that cookie?
Upvotes: 3
Views: 1803
Reputation: 692161
You should not change the client : you should change the design of your app. HTMLUnit does what any real browser would do in this case : reject the cookie. A web site may not set a cookie for another domain, for security (and privacy) reasons.
Upvotes: 1