★ wanayoo — archive 1999 http://wdvl.internet.com/Authoring/Scripting/Tutorial/java_post_to_server.htmlNouvelle recherche | Portail wanayoo

Let internet.com work for you! logo

internet.com
Join the free
WDVL newsletter!

home

Sending Information to a Remote Site

  • Just as it is easy to receive data from a server, it is also easy to send data to a server, or more likely, to a CGI script on a server.

  • In this case, we will use an output and print stream instead of an input stream as in the following example.

    try
      {
      Socket s = new Socket("www.extropia.com", 
                             80);
      OutputStream os = s.getOutputStream());
      PrintStream ps = new PrintStream(os);
      ps.println("POST /cgi-bin/test.cgi");
      ps.println("Content-type: plain/text");
      String string = "Hello CGI Script!";
      ps.println("Content-length: " + 
                 string.length + "\n");
      ps.println(string);
      }
    catch (IOException e)
      {
      System.out.println("Error: " + e);
      }
    

  • Of course, you could simply use the GET method by passing the data as URL encoded information by replacing the first println line above with something more like:

    ps.println("GET /cgi-bin/test.cgi?phrase=Hello+CGI+Script");

Additional Resources:

Getting Information from a Remote Site
Table of Contents
Threads

Up to => Home / Authoring / Scripting / Tutorial

Instantly look up a "techie" word using Webopedia!!


internet.com
e-commerce
WebDeveloper Network


Get Ranked Higher on Search Engines

Copyright 1999 internet.com Corporation. Legal Notices. Privacy Policy.

www.internet.com