簡體   English   中英

在 PHP 中運行 RapidAPI Skyscanner 航班搜索的 POST 創建會話時出現 405 錯誤

[英]Getting 405 error while running POST create session of RapidAPI Skyscanner flight search in PHP

我試圖從 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 ) )

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

這可能是原因,405 Method Not Allowed 意味着根本不支持 HTTP 方法。 例如,客戶端可能會在未實現 POST 或毫無意義的資源上執行 POST 請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM