在PHP中运行RapidAPI Skyscanner航班搜索的POST创建会话时收到405错误



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

require_once 'vendor/autoload.php';
require_once 'vendor/mashape/unirest-php/src/Unirest.php';
$response = UnirestRequest::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 方法 不允许 [缓存控制] => 私有 [内容类型] => application/json [日期] => 周三, 24 四月 2019 04:34:14 GMT [服务器] => RapidAPI-1.0.15 [X-RapidAPI-Region] => AWS - ap-southeast-1 [X-RapidAPI 版本] => 1.0.15 [内容长度] => 2 [连接] => 保持活动状态 (

(

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

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

相关内容

  • 没有找到相关文章

最新更新