0

I'm working on a local Ubuntu system. Now I'm trying to send a XML request to an application in a remote server through cURL. Below is the XML :

  <?php

    $xml = <<<XML
    <?xml version="1.0" encoding="UTF-8"?>
    <Student>
      <Name>John</Name>
      <Age>5</Age>
    </Student>
$url="http://www.test.com/testapp?request=";
$xml =htmlentities($xml);
echo $xml;

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml; charset=utf-8"));  
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

  $result = curl_exec($ch);
  $info = curl_getinfo($ch);
  curl_close($ch);
  return $result;  


}?>

My problem is I'm not able to connect to the web application external remote server.But, in local system the page redirects to another page .How can I trace whether my request is sent to the remote server.When I try to access the URL manually from browser, I'm able to access the web application. So what should I do to know whether the XML request is sent or not.

user3004356
  • 870
  • 4
  • 16
  • 49

2 Answers2

0

Add this line.

curl_setopt($ch, CURLOPT_VERBOSE, true);

Also this function is useful.

http://www.php.net/manual/en/function.curl-getinfo.php

$info = curl_getinfo($ch);
print_r($info);

Change this two lines

$url="http://www.test.com/testapp";
curl_setopt($ch, CURLOPT_POSTFIELDS, "request=" . $xml);

For a complete example Send XML data to webservice using php curl

Community
  • 1
  • 1
chanchal118
  • 3,551
  • 2
  • 26
  • 52
  • I tried this - `if(!curl_errno($ch)) { $info = curl_getinfo($ch); echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; } ` – user3004356 Dec 30 '13 at 07:04
  • I see it displays the following statements- `Took 0 seconds to send a request to https://www.test.com/testapp?request=` – user3004356 Dec 30 '13 at 07:06
0

In general you could use netstat to trace any request you have made from your machine.

Sony Mathew
  • 2,929
  • 2
  • 22
  • 29