如何跟踪XML请求是否发送到远程服务器中的Web应用程序[cURL]

时间:2013-12-30 06:55:43

标签: php xml curl

我正在使用本地Ubuntu系统。现在,我正在尝试通过cURL向远程服务器中的应用程序发送XML请求。以下是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;  


}?>

我的问题是我无法连接到Web应用程序外部远程服务器。但是,在本地系统中,页面重定向到另一个页面。如何跟踪我的请求是否发送到远程服务器。当我尝试要从浏览器手动访问URL,我可以访问Web应用程序。那么我该怎么做才能知道是否发送了XML请求。

2 个答案:

答案 0 :(得分:0)

添加此行。

curl_setopt($ch, CURLOPT_VERBOSE, true);

此功能也很有用。

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

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

更改这两行

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

完整的例子 Send XML data to webservice using php curl

答案 1 :(得分:0)

通常,您可以使用netstat跟踪您从计算机发出的任何请求。