使用 php curl 将 XML 数据发送到 Webservice
我正在研究arzoo的Flight API。服务器必须在简单的 POST 请求中接收已发布的数据。为了实现这一点,我正在使用PHP cURL。在API文档中,明确提到数据应按以下格式发送:
<AvailRequest>
<Trip>ONE</Trip>
<Origin>BOM</Origin>
<Destination>NYC</Destination>
<DepartDate>2013-09-15</DepartDate>
<ReturnDate>2013-09-16</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<Preferredclass>E</Preferredclass>
<Eticket>true</Eticket>
<Clientid>77752369</Clientid>
<Clientpassword>*AB424E52FB5ASD23YN63A099A7B747A9BAF61F8E</Clientpassword>
<Clienttype>ArzooINTLWS1.0</Clienttype>
<PreferredAirline></PreferredAirline>
</AvailRequest>
我已经在变量$xml中获取了上述代码。我的PHP cURL代码如下:
$URL = "http://59.162.33.102:9301/Avalability";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
if (curl_errno($ch))
{
// moving to display page to display curl errors
echo curl_errno($ch) ;
echo curl_error($ch);
}
else
{
//getting response from server
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
}
我没有得到任何回应。我已经与API提供商讨论了相同的情况,但他们在日志中发现了空请求。我是否从我这边错过了一些东西。您的回复将不胜感激。谢谢。