0
votes

The code below is not working when I access the API by accessing this file and using cURL, It gives me following error:

Curl Error Results HTTP/1.1 403 Forbidden X-Mashery-Responder: mashery-web2-lax.mashery.com X-Mashery-Error-Code: ERR_403_DEVELOPER_INACTIVE Content-Type: text/xml Accept-Ranges: bytes Content-Length: 31 Server: Mashery Proxy Date: Mon, 29 Oct 2012 18:41:23 GMT Connection: keep-alive 403 Developer Inactive

and It is working when I access it directly through the link it generates. Can some one tell me if there is any problem with how I am using the cURL ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

/**
 * Initialize the cURL session
 */
$ch = curl_init();

$city = 'Seattle';
$departure = '11/03/2012';
$arrival = '11/08/2012';
$citycode='US';
$apiKey='***************';
$cid='55505';
$locale='en_US';
$currencyCode='USD';
$minorRev='16';
$customerSessionId='0ABAA874-27EB-E913-A4E2-7B0946904C6D';
$customerIpAddress=$_SERVER['REMOTE_ADDR'];
$customerUserAgent=$_SERVER['HTTP_USER_AGENT'];



$customerUserAgent=urlencode($customerUserAgent);

$url='http://api.ean.com/ean-services/rs/hotel/v3/list?minorRev='.$minorRev.'&amp;cid='. $cid .'&amp;apiKey='. $apiKey.'&amp;customerUserAgent='.$customerUserAgent . '&amp;locale='.$locale.'&amp;currencyCode='.$currencyCode.'&_type=xml';


$xml='&lt;HotelListRequest&gt;&lt;city&gt;';
$xml .= $city;
$xml .='&lt;/city&gt;&lt;countryCode>';
$xml .= $citycode;
$xml .='&lt;/countryCode&gt;&lt;arrivalDate&gt;';
$xml .= $arrival;
$xml .='&lt;/arrivalDate&gt;&lt;departureDate&gt;';
$xml .= $departure;
$xml .='&lt;/departureDate&gt;&lt;/HotelListRequest&gt;';


$main = $url .'&xml='. $xml;
echo $main;
 /**
 * Set the URL of the page or file to download.
 */
 curl_setopt($ch, CURLOPT_URL, $main);

  curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 65000);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml" ));
   curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );





 /**
 * Ask cURL to return the contents in a variable instead of simply echoing them to  the browser.
 */
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

 /**
 * Execute the cURL session
 */
 $contents = curl_exec ($ch);


 /**
 * Close cURL session
 */
 curl_close ($ch);

 echo '<br /><br />Curl Error';
echo curl_error($ch);
echo '<br />Results <br />' . $contents;


?>
</body>
</html>
1

1 Answers

0
votes

In your $url construction, don't encode the ampersands with &amp; between each parameter. The parameter values (e.g. "xml" param value) should be encoded, but the ampersands that delimit each GET request parameter in the URI should not be encoded.

So, your code creates this $main value:

http://api.ean.com/ean-services/rs/hotel/v3/list?minorRev=16&amp;cid=55505&amp;apiKey=********&amp;customerUserAgent=&amp;locale=en_US&amp;currencyCode=USD&_type=xml&xml=&lt;HotelListRequest&gt;&lt;city&gt;Seattle&lt;/city&gt;&lt;countryCode>US&lt;/countryCode&gt;&lt;arrivalDate&gt;11/08/2012&lt;/arrivalDate&gt;&lt;departureDate&gt;11/03/2012&lt;/departureDate&gt;&lt;/HotelListRequest&gt;

And it should be:

http://api.ean.com/ean-services/rs/hotel/v3/list?minorRev=16&cid=55505&apiKey=********&customerUserAgent=&locale=en_US&currencyCode=USD&_type=xml&xml=&lt;HotelListRequest&gt;&lt;city&gt;Seattle&lt;/city&gt;&lt;countryCode>US&lt;/countryCode&gt;&lt;arrivalDate&gt;11/08/2012&lt;/arrivalDate&gt;&lt;departureDate&gt;11/03/2012&lt;/departureDate&gt;&lt;/HotelListRequest&gt;

Take care, Neil @ Mashery