looking for HttpURLConnection implementation

A

Angus Parvis

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
 
S

Sudsy

Angus said:
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.
 
A

Angus Parvis

Sudsy said:
Angus Parvis wrote:


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

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

noname

Angus said:
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/
 
B

Babu Kalakrishnan

Angus said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top