Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 23, 2012, 04:44:27 PM

Pages: [1]   Go Down
  Print  
Author Topic: How to do a HTTP Post request from a servlet  (Read 420 times)
folkxing
Spacescooter Operator
*****
Offline Offline

Posts: 36


« on: September 13, 2002, 01:21:00 AM »

I need to do a HTTP Post request from a servlet instead of from a webpage.  How can i do this?  Also, if this is possible, how do I pass along the parameters from the servlet?
Logged
RichieRich
Space Explorer
***
Offline Offline

Posts: 6


WWW
« Reply #1 on: September 16, 2002, 02:26:00 AM »

Open up a HttpURLConnection
Set the following properties:
setDoInput(true)
setDoOutput(true)
setUseCaches(false)
setRequestProperty("Content-type", "application/x-www-
form-urlencoded")
setRequestProperty("Content-length", "" + (data length));
---
Get your outputstream
DataOutputStream dos = new DataOutputStream
(urlConn.getOutputStream());
dos.writeBytes("name1=value1&name2=value2&name3=value3&...");
dos.close();

Hope this helps,
Logged

Richard Burton
Software Developer
Pages: [1]   Go Up
  Print  
 
Jump to: