0

我正面临获得卷曲响应的问题

测试.xml

<?xml version="1.0" encoding="UTF-8"?>
<MMTHotelSearchRequest Offset="0" Rows="500">
    <POS>
      <Requestor type="B2BAgent" idContext="AFF" id="AFF13856" channel="B2BWeb"/>
      <Source iSOCurrency="INR"/>
   </POS>
    <RequestHotelParams>
        <CityCode>DEL,XRO</CityCode>
    </RequestHotelParams>
    <RequiredFields>hotelInfo,facilitiesInfo,areaInfo,contactInfo,roomsInfo,mediaInfo</RequiredFields>
</MMTHotelSearchRequest>




<?php
$filename = "test.xml";
$handle = fopen($filename, "r");
$xml = fread($handle, filesize($filename));
fclose($handle);

$url = "https://apim-gateway.mmtcloud.com/mmt-htlsearch/1.0/staticsearch/v1.0/hotelData";
$headers = array(             
                            "Content-type: text/xml;charset=\"utf-8\"", 
                            "Accept: text/xml", 
                            "Cache-Control: no-cache", 
                            "Pragma: no-cache", 
                            "Content-length: ".strlen($xml),
                            ); 


            $soap_do = curl_init(); 
            curl_setopt($soap_do, CURLOPT_URL,            $url);   
            curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 60); 
            curl_setopt($soap_do, CURLOPT_TIMEOUT,        60); 
            curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
            curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);  
            curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); 
            curl_setopt($soap_do, CURLOPT_POST,           true ); 
            curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $xml); 
            curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $headers); 


            $result = curl_exec($soap_do);

            print_r($result);
?>

我得到以下错误

HTTP 状态 415 -

类型状态报告

信息

描述 服务器拒绝此请求,因为请求实体的格式不受请求的方法 () 的请求资源支持。

请帮我。

4

1 回答 1

1

CURLOPT_POSTFIELDS应该是键值/对的数组。您应该创建一个数组,将 xml 数据添加到正确的键字段并使用 curl 发送该数据。

我添加了一个示例:

<?php
$filename = "test.xml";
$handle = fopen($filename, "r");
$xml = fread($handle, filesize($filename));
fclose($handle);

$url = "https://apim-gateway.mmtcloud.com/mmt-htlsearch/1.0/staticsearch/v1.0/hotelData";
$headers = array(             
                            "Content-type: text/xml;charset=\"utf-8\"", 
                            "Accept: text/xml", 
                            "Cache-Control: no-cache", 
                            "Pragma: no-cache", 
                            "Content-length: ".strlen($xml),
                            ); 
$postdata = array("fieldkey" => $xml); //<-------------

        $soap_do = curl_init(); 
        curl_setopt($soap_do, CURLOPT_URL,            $url);   
        curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 60); 
        curl_setopt($soap_do, CURLOPT_TIMEOUT,        60); 
        curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
        curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);  
        curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); 
        curl_setopt($soap_do, CURLOPT_POST,           true ); 
        curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $postdata); //<----------- 
        curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $headers); 

        $result = curl_exec($soap_do);

        print_r($result);
?>
于 2014-10-15T13:51:20.793 回答