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.
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 theSet-Cookieheader in the response. (If you do want to stick withURLConnection, that gives you the headers too… I’m just generally wary of it being a pain compared with other HTTP libraries.)Set-Cookieis used by the server to send cookies to the client; theCookieheader is used by the client to send cookies back to the server. See RFC 2965 and RFC 6265 for more information.