From: Ronald B. <rb...@rb...> - 2017-02-02 15:07:32
|
Now i'm confused... > Suppose, I am using HTMLUnit in JS disabled mode and when I interact with a server and the server sends an HTML page > which has a Javascript for setting cookies using setcookie method. >Please note that the response header does not contain > Set-Cookie. > > How does HTMLUnit handle the above situation?. It looks like I need to enable JS. Is there a way to solve/work around this issue? I think i have proposed a solution: replace mgr.addCookie(new Cookie(".jobdiva.com", "COMPANYLOGOLOCATION", "my_data", "/", -1, false)); by webClient.addCookie("COMPANYLOGOLOCATION=my_data; Domain=.jobdiva.com; Path=/"); This should work. RBRi > >On 2 February 2017 at 01:59, Ronald Brill <rb...@rb...> wrote: > >> Ok Vasu, >> >> this was a really tricky one. >> >> You are interacting directly with the cookie manager in this way >> >> final CookieManager mgr = webClient.getCookieManager(); >> mgr.addCookie(new Cookie(".jobdiva.com", "COMPANYLOGOLOCATION", >> "my_data", "/", -1, false)); >> >> In this case you are responsible for all the cookie properties. >> But there is some magic, if a web site sends a comparable cookie like >> "COMPANYLOGOLOCATION=my_data; Domain=.jobdiva.com; Path=/". >> Internally there is some cleanup before the cookie is added to the cookie >> manager, in this case the leading dot will be removed from the domain. >> When sending th cookies back the cookie matches now, because of the >> removed dot at the start. This logic is more or less part of HttpClient >> already. >> >> Ok, and what to do now? >> >> I guess you like to simulate some cookies sent from the server before you >> are starting your request. I think the more correct way is to interact with >> the webClient instead of the CookieManager directly because there is a way >> to use the same magic as we use >> when processing cookies from the real response. >> >> webClient.addCookie("COMPANYLOGOLOCATION=my_data; Domain=. >> jobdiva.com; Path=/"); >> >> is your friend. >> Hope that helps. >> >> RBRi |