user3049475
user3049475

Reputation: 33

php curl help on HTTP Status 415

I'm facing issue for getting curl response

test.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);
?>

I'm getting below error

HTTP Status 415 -

type Status report

message

description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().

Please help me.

Upvotes: 0

Views: 1397

Answers (1)

Jerodev
Jerodev

Reputation: 33186

The CURLOPT_POSTFIELDS should be an array of key value/pairs. You should create an array, add the xml data to the correct key field and send that data using curl.

I have added an example:

<?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);
?>

Upvotes: 1

Related Questions