looking for HttpURLConnection implementation

Discussion in 'Java' started by Angus Parvis, Aug 19, 2004.

  1. Angus Parvis

    Angus Parvis Guest

    Greetings,

    Does anyone know a publicy available implementation of the abstract
    java.net.HttpURLConnection? I want to do send a "HTML form" via HTTP
    POST - maybe you know another implementation, that would come in handy.

    Thanks for your help,

    Angus
     
    Angus Parvis, Aug 19, 2004
    #1
    1. Advertising

  2. Andrew Thompson, Aug 19, 2004
    #2
    1. Advertising

  3. Angus Parvis

    Sudsy Guest

    Angus Parvis wrote:
    > Greetings,
    >
    > Does anyone know a publicy available implementation of the abstract
    > java.net.HttpURLConnection? I want to do send a "HTML form" via HTTP
    > POST - maybe you know another implementation, that would come in handy.


    All you have to do is cast the result of URL#openConnection. Here's
    some sample code:

    URL url = null;
    HttpURLConnection conn = null;
    PrintWriter pw = null;

    try {
    url = new URL( "http://www.usps.gov/cgi-bin/zip4/ctystzip2" );
    conn = (HttpURLConnection) url.openConnection();
    conn.setDoOutput( true );
    pw = new PrintWriter( new OutputStreamWriter(
    conn.getOutputStream() ) );
    pw.println( "ctystzip=10111" );
    pw.close();
    // do something with conn.getInputStream()
    }
    catch( Exception e ) {
    ...
    }

    Invoking setDoOutput with an argument of true is what makes it a
    POST request, BTW.
     
    Sudsy, Aug 19, 2004
    #3
  4. Angus Parvis

    Angus Parvis Guest

    Sudsy wrote:

    > Angus Parvis wrote:


    >> Does anyone know a publicy available implementation of the abstract
    >> java.net.HttpURLConnection? I want to do send a "HTML form" via HTTP
    >> POST - maybe you know another implementation, that would come in handy.

    >
    >
    > All you have to do is cast the result of URL#openConnection. Here's
    > some sample code:


    Great, I'll try that out. Thanks :)
     
    Angus Parvis, Aug 19, 2004
    #4
  5. Angus Parvis

    noname Guest

    Angus Parvis wrote:

    > Greetings,
    >
    > Does anyone know a publicy available implementation of the abstract
    > java.net.HttpURLConnection? I want to do send a "HTML form" via HTTP
    > POST - maybe you know another implementation, that would come in handy.
    >
    > Thanks for your help,
    >
    > Angus


    Other posts have mentioned the java.net.URL.openConnection(), so I'll
    just add that you may also want to check out the open-source HTTP Client
    over at the Jakarta Project site. It's really good IMO.

    Here's a link:
    http://jakarta.apache.org/commons/httpclient/
     
    noname, Aug 19, 2004
    #5
  6. Angus Parvis wrote:
    > Sudsy wrote:
    >
    >> Angus Parvis wrote:

    >
    >
    >>> Does anyone know a publicy available implementation of the abstract
    >>> java.net.HttpURLConnection? I want to do send a "HTML form" via HTTP
    >>> POST - maybe you know another implementation, that would come in handy.

    >>
    >>
    >>
    >> All you have to do is cast the result of URL#openConnection. Here's
    >> some sample code:

    >
    >
    > Great, I'll try that out. Thanks :)


    Let me also warn you that HttpClient implementation of Sun is far from complete
    and even somewhat flawed in several areas. In all probability it was written
    solely for the purpose of classloading, and not much more (Very similar to the
    classes in java.util.zip / jar packages - you have to be very wary of using them
    for any other purpose).

    The jakarta commons implementation (which another poster suggested) is supposed
    to be quite good - and another freeware implementation is available at
    http://www.innovation.ch/java/HTTPClient/ (though I wonder if it is still
    maintained)

    BK
     
    Babu Kalakrishnan, Aug 20, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip
    Replies:
    8
    Views:
    714
  2. Siegfried Ertl

    HttpURLConnection

    Siegfried Ertl, Nov 30, 2003, in forum: Java
    Replies:
    1
    Views:
    2,302
    Sudsy
    Nov 30, 2003
  3. David G
    Replies:
    3
    Views:
    3,024
    David G
    Dec 16, 2003
  4. igoR Buttler
    Replies:
    1
    Views:
    12,384
  5. Niels Campbell

    HttpURLConnection timeout solution

    Niels Campbell, Jan 23, 2004, in forum: Java
    Replies:
    6
    Views:
    44,092
    dadada
    Oct 27, 2006
Loading...

Share This Page