Jo�o Robertson Kramer Santana wrote:

>         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 ?

    Maybe there is some simpliest method but I use something like this:

<code>
// assume I have created socket to required host and port 80
// get output
PrintStream output = new PrintStream(socket.getOutputStream());
// get input
InputStream input = socket.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
// URL
String url = "/path/to/myScript.cgi";
// Host
String host = "my.server.com";
// POST
output.println("POST " + url + " HTTP/1.1");
// Host
output.println("Host: " + host);
// Accept - you can put here any mime type(s) you need
output.println("Accept: text/html");
// Content parameters
// do NOT forget the last "\n"
// it means the end of the request's header!!!
output.println("Content-Encoding: 8859_1\n"
                +"Content-Type: application/x-www-form-urlencoded\n"
                +"Content-Length: " + data.length() + "\n");
// and now the data
output.println(java.net.URLEncoder.encode("parameter1="+value1)
                +"&"+java.net.URLEncoder.encode("parameter2="+value2)
                // ... more parameters ...
               );
// and now read input (CGI's output)
String line = in.readLine();
while (line!=null)
{
   // do something with the line
   ...
   // read next line
   line = in.readLine();
}
</code>

   I hope it wil help you.

J.Ch.
--
Ing. Jozef Chocholacek                  Qbizm Technologies, Inc.
Chief Project Analyst                   ... the art of internet.
________________________________________________________________
Kralovopolska 139                          tel: +420 5 4124 2414
601 12 Brno, CZ      http://www.qbizm.com  fax: +420 5 4121 2696

___________________________________________________________________________
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