4

我正在尝试从 POST 创建会话的响应中获取位置标头,但出现 405 错误。除了位置标头之外,我得到的所有其他响应。

require_once 'vendor/autoload.php';
require_once 'vendor/mashape/unirest-php/src/Unirest.php';

$response = Unirest\Request::post("https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/pricing/v1.0",
  array(
    "X-RapidAPI-Host" => "skyscanner-skyscanner-flight-search-v1.p.rapidapi.com",
    "X-RapidAPI-Key" => "d0f49284f7mshba8a904a96cf3acp19aa44jsnb4056f027c69",
    "Content-Type" => "application/x-www-form-urlencoded"
  ),
  array(
    "inboundDate" => "2019-04-25",
    "cabinClass" => "business",
    "children" => 0,
    "infants" => 0,
    "country" => "IN",
    "currency" => "INR",
    "locale" => "en-US",
    "originPlace" => "BLR-sky",
    "destinationPlace" => "DEL-sky",
    "outboundDate" => "2019-04-26",
    "adults" => 1
  )
);

 print_r($response);

我期待这种类型的回应:

"cache-control": "private"
"content-type": "application/json"
"date": "Wed, 24 Apr 2019 05:01:39 GMT"
"location": "http://partners.api.skyscanner.net/apiservices/pricing/hk1/v1.0/42ba47f0-314c-41fa-987d-fb8c5862309b"
"server": "RapidAPI-1.0.15"
"x-rapidapi-region": "AWS - ap-southeast-1"
"x-rapidapi-version": "1.0.15"
"content-length": "2"
"connection": "Close"

但是,实际输出是:

Unirest\Response Object ( [code] => 405 [raw_body] => {} [body] => stdClass Object () [headers] => Array ([0] => HTTP/1.1 405 Method Not Allowed [Cache-Control ] => private [Content-Type] => application/json [Date] => Wed, 24 Apr 2019 04:34:14 GMT [Server] => RapidAPI-1.0.15 [X-RapidAPI-Region] => AWS - ap-southeast-1 [X-RapidAPI-Version] => 1.0.15 [Content-Length] => 2 [Connection] => keep-alive ) )

4

1 回答 1

0

我假设您在 RapidAPI Hub 上使用Skyscanner Flight Search API。有趣的是,我看不到此 API 支持的任何 POST 请求。

这可能是原因,405 Method Not Allowed 意味着根本不支持 HTTP 方法。例如,客户端可能会对未实现 POST 或没有意义的资源执行 POST 请求。

于 2021-09-07T09:06:36.887 回答