Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading Cookies from HttpUrlConnection - Set-Cookie Header

 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic