-3

I'm new to cURL, can we do the same thing in httpclient and httppost? If yes, what is the equivalent code for the cURL below.

$xml = '<test>';
$xml .= '<date>'.date("d/m/Y", time()).'</date>';
$xml .= '<time>'.date("H:m:s", time()).'</time>';
$xml .= '<param>'.$input.'</param>';
$xml .= '</test>';

// get the host
$curl=curl_init("http://someurl.com");

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($curl, CURLOPT_VERBOSE, 1); // debug
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (FD)");
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));

$response = curl_exec($curl);
June Leow
  • 102
  • 1
  • 16
  • 1
    -1 for question: "translate my code from one language/library to another" ... and yes, it is possible – Selvin Jun 09 '14 at 14:15
  • 1
    We are not a code translation service. – Marc B Jun 09 '14 at 14:17
  • 2
    This question appears to be off-topic because it is asking for others to translate code, without showing any effort to do so before asking the question. – Bryan Herbst Jun 09 '14 at 15:13
  • I tried to reproduce the request with httpclient but it doesn't work so I figure I should post a question while I was working on it. Sorry anyway. – June Leow Jun 09 '14 at 17:17

1 Answers1

0

The apache http client makes this a piece of cake. Check the following tutorial for more details : http://www.vogella.com/tutorials/ApacheHttpClient/article.html

http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/