简体   繁体   English

PHP调用时的SkyScanner API错误

[英]SkyScanner API error when called by PHP


I did exactly as shown in the API documentation 我完全按照API文档中的说明完成了
http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingList http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingList
but when i call it returns this error 但是当我调用它时会返回此错误

HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: application/json Date: Sat, 04 Jun 2016 06:23:48 GMT Connection: close Content-Length: 2 {}

and here is my code in PHP 这是我在PHP中的代码

<?
$url = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/';
$data = array('apiKey' => 'de995438234178656329029769192274', 'country' => 'BR', 'currency' => 'BRL',
'locale' => 'pt-BR', 'originplace' => 'SDU-iata', 'destinationplace' => 'GRU-iata', 'outbounddate' => '2016-09-23', 
$headers = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
printf($result);
?>

any idea what is going wrong? 什么是错的?

thanks in advance for any kind 提前感谢任何一种

So I think the PHP is sending the wrong request type, because the HTTP headers were being sent as an array (so defaults to 'multipart/formdata'). 所以我认为PHP发送了错误的请求类型,因为HTTP标头是作为一个数组发送的(因此默认为'multipart / formdata')。 If you use http_build_query on that array, it is sent correctly as 'x-www-form-urlencoded'. 如果您在该阵列上使用http_build_query,它将以'x-www-form-urlencoded'正确发送。

I've tidied things up, removed some duplication in the curl options, and correctly get a 201 response on your example now: 我已整理了一些东西,删除了卷曲选项中的一些重复内容,并且正确地在您的示例中获得了201响应:

<?
$url = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/';
$data = array('apiKey' => 'de995438234178656329029769192274', 'country' => 'BR', 'currency' => 'BRL',
'locale' => 'pt-BR', 'originplace' => 'SDU', 'destinationplace' => 'GRU', 'outbounddate' => '2016-09-23', 'locationschema' => 'Iata', 'adults' => 1);   
$httpdata = http_build_query($data);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpdata);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>

Hope that helps, I'll keep an eye on the thread in case of anything else - feel free to drop us a query or check the FAQs here: https://support.business.skyscanner.net/hc/en-us 希望有所帮助,我会密切关注线程以防万一 - 请随时给我们提问或查看常见问题解答: https//support.business.skyscanner.net/hc/en-us

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM