Reputation: 9032
Hi I'm trying to test whether a site returns a cookie or not. I'm very new to Java.
I Have opened the connection using :
conn = "https://mysite.com/".toURL().openConnection()
Having opened the connection, how to test whether the site mysite
returns the cookie or not?
Thanks in advance.
Upvotes: 3
Views: 120
Reputation: 1500535
To start with, I'd suggest using a higher level API than URLConnection
. There are various HTTP libraries around. Some of them would even work out all the cookies for you - but even if they don't... you just need to check for the Set-Cookie
header in the response. (If you do want to stick with URLConnection
, that gives you the headers too... I'm just generally wary of it being a pain compared with other HTTP libraries.)
Set-Cookie
is used by the server to send cookies to the client; the Cookie
header is used by the client to send cookies back to the server. See RFC 2965 and RFC 6265 for more information.
Upvotes: 4