How to do http POST with JAVA?

R

rodrigo.rodenbeek

Hello, guys.

I would like to knoe how to do following example in java, instead of
PHP

--- start ---
$id = 1;
$postUrlData = array( 'id' => $id );

$ch = curl_init();

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, "http://mysite/some-cgi" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postUrlData );

$data_returned = curl_exec( $ch );
curl_close( $ch );

if( $data_returned == "ok" )
echo "<pre>it's ok</pre>";
--- end ---

Regards,
Rodrigo
 
T

Thomas Fritsch

I would like to knoe how to do following example in java, instead of
PHP

--- start ---
$id = 1;
$postUrlData = array( 'id' => $id );

$ch = curl_init();

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, "http://mysite/some-cgi" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postUrlData );

$data_returned = curl_exec( $ch );
curl_close( $ch );

if( $data_returned == "ok" )
echo "<pre>it's ok</pre>";
--- end ---

You can use URL and URLConnection as described in
http://javaalmanac.com/egs/java.net/Post.html
 

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,820
Messages
2,569,722
Members
45,510
Latest member
ThaliaMaxi

Latest Threads

Top