amadeus api faultstring Content-Length 丢失 stackoverflow
amadeus api faultstring Content-Length is missing stackoverflow
我正在努力让我的拳头 Amadeus API 打电话上班。
•• 我能够取回令牌••
$url = 'https://test.api.amadeus.com/v1/security/oauth2/token';
$curls = curl_init();
curl_setopt($curls, CURLOPT_URL, $url);
curl_setopt($curls, CURLOPT_POST, true);
curl_setopt($curls, CURLOPT_POSTFIELDS, 'grant_type=client_credentials&client_id=--key--&client_secret=--secret--');
curl_setopt($curls, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$token = curl_exec($curls);
curl_close($curls);
但是拿到token之后,我就不能再继续了....
当我尝试这段代码时
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_TIMEOUT=>469,
CURLOPT_URL => "https://api.amadeus.com/v1/shopping/flight-dates?origin=NYC&destination=LON&oneWay=false&nonStop=false",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array("Authorization: Bearer --token--")
));
$response = curl_exec($curl); $err = curl_error($curl); curl_close($curl);
echo $response;
我明白了
{"fault":{"faultstring":"Content-Length is missing","detail":{"errorcode":"messaging.adaptors.http.flow.LengthRequired"}}}
我错过了什么?
请在下面找到一个工作示例:
$url = 'https://test.api.amadeus.com/v1/shopping/flight-dates?origin=NYC&destination=MOW&oneWay=false&nonStop=false';
$curls = curl_init();
curl_setopt($curls, CURLOPT_URL, $url);
curl_setopt($curls, CURLOPT_HTTPHEADER, array('Authorization: Bearer access_token'));
$result = curl_exec($curls);
if (curl_errno($curls)) {
echo 'Error:' . curl_error($curls);
}
print_r ($result);
curl_close ($curls);
注:
- 我将目的地更改为 NYC 到 LON 不是我们在测试环境中拥有的数据集的一部分(您可以找到列表 here)。
- 您使用的 URL 是
api.amadeus.com
,这是生产环境,但您从 test.api.amadeus.com
获得令牌,这是测试环境。在示例中,我调用测试环境。
我能够做到 shell_exec 并且它有效。
url (test.api.amadeus.com.......) 在 php cURL 中无法正常工作。
我的工作代码:
$shopping_flight_destinations_par = 'https://test.api.amadeus.com/v1/shopping/flight-destinations?origin=PAR&maxPrice=200';
$amadex_cmd = "/usr/bin/curl -X GET '".$shopping_flight_destinations_par."' -H 'Authorization: Bearer ".$amadeus_token."'";
$amadex_jsond = json_decode(shell_exec($amadex_cmd),true);
echo '<pre>'; var_dump($amadex_jsond); echo '</pre>';
我正在努力让我的拳头 Amadeus API 打电话上班。
•• 我能够取回令牌••
$url = 'https://test.api.amadeus.com/v1/security/oauth2/token';
$curls = curl_init();
curl_setopt($curls, CURLOPT_URL, $url);
curl_setopt($curls, CURLOPT_POST, true);
curl_setopt($curls, CURLOPT_POSTFIELDS, 'grant_type=client_credentials&client_id=--key--&client_secret=--secret--');
curl_setopt($curls, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$token = curl_exec($curls);
curl_close($curls);
但是拿到token之后,我就不能再继续了....
当我尝试这段代码时
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_TIMEOUT=>469,
CURLOPT_URL => "https://api.amadeus.com/v1/shopping/flight-dates?origin=NYC&destination=LON&oneWay=false&nonStop=false",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array("Authorization: Bearer --token--")
));
$response = curl_exec($curl); $err = curl_error($curl); curl_close($curl);
echo $response;
我明白了
{"fault":{"faultstring":"Content-Length is missing","detail":{"errorcode":"messaging.adaptors.http.flow.LengthRequired"}}}
我错过了什么?
请在下面找到一个工作示例:
$url = 'https://test.api.amadeus.com/v1/shopping/flight-dates?origin=NYC&destination=MOW&oneWay=false&nonStop=false';
$curls = curl_init();
curl_setopt($curls, CURLOPT_URL, $url);
curl_setopt($curls, CURLOPT_HTTPHEADER, array('Authorization: Bearer access_token'));
$result = curl_exec($curls);
if (curl_errno($curls)) {
echo 'Error:' . curl_error($curls);
}
print_r ($result);
curl_close ($curls);
注:
- 我将目的地更改为 NYC 到 LON 不是我们在测试环境中拥有的数据集的一部分(您可以找到列表 here)。
- 您使用的 URL 是
api.amadeus.com
,这是生产环境,但您从test.api.amadeus.com
获得令牌,这是测试环境。在示例中,我调用测试环境。
我能够做到 shell_exec 并且它有效。 url (test.api.amadeus.com.......) 在 php cURL 中无法正常工作。
我的工作代码:
$shopping_flight_destinations_par = 'https://test.api.amadeus.com/v1/shopping/flight-destinations?origin=PAR&maxPrice=200';
$amadex_cmd = "/usr/bin/curl -X GET '".$shopping_flight_destinations_par."' -H 'Authorization: Bearer ".$amadeus_token."'";
$amadex_jsond = json_decode(shell_exec($amadex_cmd),true);
echo '<pre>'; var_dump($amadex_jsond); echo '</pre>';