This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to send a cookie in HTTP post Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to send a cookie in HTTP post " Watch "How to send a cookie in HTTP post " New topic

How to send a cookie in HTTP post

Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
Hi ,

I have to send a cookie through an http post from a java program .

For some other reasons I am using a HttpsUrlConnection to make a conenction with the server.
How can I send the cookie?

Sharad Agarwal
Ranch Hand

Joined: Sep 11, 2002
Posts: 167
It will be useful to look at the format for a URL request:

You will need to use the HttpsUrlConnection.setRequestProperty() method to set the Cookie.

(If using HttpsUrlConnection is not a mandate, please consider using Apache HttpClient).
[ July 15, 2005: Message edited by: Sharad Agarwal ]

Alco-Haul: We move spirits.
Demented Deliberations of a Dilettante
kotesh rao

Joined: Jun 08, 2005
Posts: 11

StringBuffer sb1 = new StringBuffer();

sb1.append(<Name> );
sb1.append(< value >+ ";");

one more

sb1.append(<Name> );
sb1.append(< value >+ ";");

specify name and value for cookies..if u have more just repeat above 3 lines.

then add cookies to url header.

header.append("Cookie: ");

//write header information.

hope this will help u.
I agree. Here's the link:
subject: How to send a cookie in HTTP post
It's not a secret anymore!