目前正在使用Sabre Dev Studio的测试开发人员帐户并尝试使用他们的REST Api - Instaflights_Search。
我正在创建身份验证并获取访问令牌,但是当我尝试发送请求时出现问题。我使用curl和php创建标题。
function callRestApi($url,$access_token) {
$ch = curl_init();
$header = array();
$header[] = "Authorization: Bearer " .$access_token;
$header[] = "Accept: application/json";
$header[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result,true);
}
$url = "https://api.test.sabre.com/v1/shop/flights?origin=JFK&destination=LAX&departuredate=2016-05-30&returndate=2016-05-31";
$access_token = callForToken();
$server_response = callRestApi($url,$access_token);
Sabre的回应是:
array(5) {
["status"]=>
string(12) "NotProcessed"
["type"]=>
string(10) "Validation"
["errorCode"]=>
string(30) "ERR.2SG.CLIENT.INVALID_REQUEST"
["timeStamp"]=>
string(29) "2016-05-19T22:36:51.041-05:00"
["message"]=>
string(60) "Request is invalid: The request should have the JSON payload"
}
HTTP 1/1请求标头读作:
* Hostname was found in DNS cache
* Trying 151.193.52.94...
* Connected to api.test.sabre.com (151.193.52.94) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
* SSL connection using TLSv1.2 / AES256-SHA
* Server certificate:
* subject: C=US; ST=Texas; L=Southlake; O=Sabre, Inc.; OU=Internet Services; CN=api.test.sabre.com
* start date: 2015-02-25 00:00:00 GMT
* expire date: 2017-03-21 23:59:59 GMT
* subjectAltName: api.test.sabre.com matched
* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4
* SSL certificate verify ok.
> GET /v1/shop/flights?origin=JFK&destination=LAX&departuredate=2016-05-30&returndate=2016-05-05&onlineitinerariesonly=n&limit=10&offset=1&eticketsonly=n&sortby=totalfare&order=asc&sortby2=departuretime&order2=asc&pointofsalecountry=US HTTP/1.1
Host: api.test.sabre.com
Authorization: Bearer T1FNEWIhYyxjzQJ/Fh4oPfgkjU4s+R/xAxglSqD2oC4kYcCAnPcIv+bbV9sTu3KHxdpQ+zRKUsTGmpfhQT//Djx+3yDNZUcypKrbjzIzjVJvDPI+PyH5bT4F88Gcse//7hjcrz5sCRXkqwqjb1ceaBhGV2hr0t47XwBcjEvPg2I92FtFsqNw7V8NrcPfBVFxnZAbqESJ+zUQH6mSeaWa1h3Rc04g4szipQhHWDnR+sneH8ePdHKPQaoX3M44YMRvviOV8yEBYwTg**
Accept: application/json
Content-Type: application/json
< HTTP/1.1 400 Bad Request
< Date: Fri, 20 May 2016 03:15:28 GMT
< Content-Type: application/json
< Content-Length: 207
<
* Connection #0 to host api.test.sabre.com left intact
任何想法可能是标题的问题?
于2016年5月23日编辑 用于构建以下请求标头的更正版本:
function callRestApi($url,$access_token) {
$header2 = array(
'Authorization : Bearer '.$access_token,
'Accept : */*'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header2);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result,true);
}
答案 0 :(得分:1)
https://github.com/SabreDevStudio/SACS-Php
它使用的是IntaFlights和curl,所以它可能提供了一种方法来处理您正在测试的API和您的环境。
如果不适合你,请随意添加问题。
答案 1 :(得分:0)
好吧,我注意到两件事情可能会指向正确的方向:
希望这有帮助。