wood burning stoves*
The moose likes Sockets and Internet Protocols and the fly likes Reading Cookies from HttpUrlConnection - Set-Cookie Header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Reading Cookies from HttpUrlConnection - Set-Cookie Header" Watch "Reading Cookies from HttpUrlConnection - Set-Cookie Header" New topic
Author

Reading Cookies from HttpUrlConnection - Set-Cookie Header

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
I have code in place which creates an HttpUrlConnection and then needs to read the cookies. I've noticed that if I iterate through the headers returned:




...the cookie name=value always appears first in the string hdrString (as opposed to path=/; domain=.whatever.com )

Does anyone know if this is a requirement? That the cookie name=value always appears first? If so I am going to write my code to rely on that...


James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
Update - according to wikipedia the name=value is first...

Cookie attributes
Example of an HTTP response from google.com, which sets a cookie with attributes.

Beside the name/value pair, a cookie may also contain an expiration date, a path, a domain name, and whether the cookie is intended only for encrypted connections. RFC 2965 also specifies that cookies must have a mandatory version number, but this is usually omitted. These pieces of data follow the name=newvalue pair and are separated by semicolons. For example, a cookie can be created by the server by sending a line Set-Cookie: name=newvalue; expires=date; path=/; domain=.example.org.


http://en.wikipedia.org/wiki/HTTP_cookie


Can anyone else verify?
 
 
subject: Reading Cookies from HttpUrlConnection - Set-Cookie Header
 
Similar Threads
Persistent Cookies with Servlets
Cookie
how to send session info from Applet to servlet?
Why isn't my cookie being set?
Steal a session