Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Servlets
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Servlets
How to send a cookie in HTTP post
Archana Annamaneni
Ranch Hand
Posts: 147
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Sharad Agarwal
Ranch Hand
Posts: 167
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It will be useful to look at the format for a URL request:
Host: <a href="http://www.google.com" target="_blank" rel="nofollow">www.google.com</a> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Referer: <a href="http://www.google.com/" target="_blank" rel="nofollow">http://www.google.com/</a> Cookie: BunchOfStuffHere
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
Greenhorn
Posts: 11
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to recive / return cookies to server?
Sending HTTP POST, something's wrong...
Cookie question
why i can't get cookie from a special web site?
handling cookies with URLConnection
More...