How to send a cookie in a URLConnection?
cookies, java, urlconnection
Solution
Well, if you are only setting a cookie I guess you could simply do like:
urlConn.setRequestProperty("Cookie", "user=mary17; domain=airtravelbargains.com; path=/autos");
If you're setting more than one cookie than you could probably use the `addRequestProperty` method instead.
For the expires attribute make sure to use the format: Weekday, DD-Mon-YY HH:MM:SS GMT.
The only legal time zone is GMT, and the separators between the elements of the date must be dashes.
Problem
What is the proper way to send a 'full' cookie across a URLConnection? I've been using: ``` URL url = new URL(page); URLConnection urlConn = url.openConnection(); urlConn.setRequestProperty("Cookie", myCookie); urlConn.setUseCaches(true); urlConn.connect(); ``` The myCookie value is testCookie=d1lEZk9rSHd3WnpBd2JkWGRhN1RYdz09OkEwQ21pSFJVZzBpVDhhUENaK3ZPV2c9PQ Is there a way to send the Path,Domain, and Expires with it? Do you need to encode the value in some way?