当我通过访问此文件并使用 cURL 访问 API 时,下面的代码不起作用,它给了我以下错误:
卷曲错误结果 HTTP/1.1 403 禁止 X-Mashery-Responder:mashery-web2-lax.mashery.com X-Mashery-Error-Code:ERR_403_DEVELOPER_INACTIVE 内容类型:文本/xml 接受范围:字节内容长度:31 服务器:Mashery 代理 日期:2012 年 10 月 29 日星期一 18:41:23 GMT 连接:keep-alive 403 Developer Inactive
当我通过它生成的链接直接访问它时它正在工作。有人可以告诉我使用 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.'&cid='. $cid .'&apiKey='. $apiKey.'&customerUserAgent='.$customerUserAgent . '&locale='.$locale.'&currencyCode='.$currencyCode.'&_type=xml';
$xml='<HotelListRequest><city>';
$xml .= $city;
$xml .='</city><countryCode>';
$xml .= $citycode;
$xml .='</countryCode><arrivalDate>';
$xml .= $arrival;
$xml .='</arrivalDate><departureDate>';
$xml .= $departure;
$xml .='</departureDate></HotelListRequest>';
$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>