• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to send a cookie in HTTP post

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

StringBuffer sb1 = new StringBuffer();

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

one more

sb1.append(<Name> );
sb1.append("=");
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: ");
header.append(sb1.toString());

//write header information.
outputStream.writeBytes(header.toString());


hope this will help u.
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic