I wrote the following code but not able to run it successfully. it is not
able to do a connection. can i just run the applicatin or do i need embed it
in a applet and invoke through an applet ?

sathish

----- Original Message -----
From: "John Waugh" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 01, 2001 4:35 AM
Subject: Re: POST from servlet


this is the base code I use

the different between implementing GET and POST
is that in the GET, query is appended onto the end of the URL before you
open the connection, and you don't use setDoInput(true);  or get an output
stream from the connection.

in the POST, you open the connection, get an output stream, and write the
query to that, either as the URLEncoded key=value pairs deliminated by the &
character if there is more than one key=value pair, else you write the
key=value pairs to separate lines.

 HttpURLConnection connection = null;
 try  {
 URL t_url = new URL(url);
 connection = (HttpURLConnection)t_url.openConnection();
 connection.setUseCaches(false);
 connection.setDoOutput(true);
 connection.setDoInput(true);

 PrintStream out = new PrintStream(connection.getOutputStream());
 String myString = "somestring";
 String myString2 = "somethingelse";
 StringBuffer query = new StringBuffer();
 query.appned("myString=");
 query.append(URLEncoder.encode(myString));
 query.append("&myString2=");
 query.append(URLEncoder.encode(myString2));
 out.print(query.toString());
 out.close();

 /* your inputstream code goes here. */

 }
 finally
 {
 if (connection != null)
 {
 connection.disconnect();
 }
 }

-----Original Message-----
From: Jo�o Robertson Kramer Santana [mailto:[EMAIL PROTECTED]]
Sent: 26 April 2001 19:47
To: [EMAIL PROTECTED]
Subject: POST from servlet


        How to make a servlet to call a Delphi CGI program or any other CGI
program that expects to receive two parameters (name and password) via POST
? I know how to do it with GET paramaters, and now I need to do it with
POST. Can someone give some examples ?

        bye

                jk

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to