php - 使用 cURL 和 PHP 发送 POST 数据以检索航空公司信息

标签 php post curl web-scraping

我总是使用 PHP Simple HTML DOM Parser 来制作网页抓取脚本,但这次我需要使用 cURL,因为表单使用 POST,我不知道为什么我的脚本不起作用。

我正在使用 Burp Proxy 来获取所有 POST 信息。

我想使用 cURL 进行查询。

这是函数,我将使用 http://flyfirstnation.com例如:

<?php

function curl_get_contents($url)
{
  $curl_moteur = curl_init();
  curl_setopt($curl_moteur, CURLOPT_URL, $url);
  curl_setopt($curl_moteur, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($curl_moteur, CURLOPT_POST, true);
  curl_setopt ($curl_moteur, CURLOPT_POSTFIELDS, '{"FormData":{"Origin":["LOS"],"VarsSessionID":"","Destination":["ABV"],"DepartureDate":["24-Jan-2014"],"ReturnDate":["28-Jan-2014","28-Jan-2014"],"Adults":"1","Children":"0","Seniors":0,"Students":0,"Infants":"0","Youths":0,"Teachers":0,"SeatedInfants":0,"EVoucher":"","SearchUser":"PUBLIC"},"IsMMBChangeFlightMode":false}');


  curl_setopt($curl_moteur,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

  curl_setopt($curl_moteur, CURLOPT_FOLLOWLOCATION, 1);
  $web = curl_exec($curl_moteur);
  curl_close($curl_moteur);
  return $web;
}


echo curl_get_contents('reservations.flyfirstnation.com');

?>

这是我收到的错误消息:

The page cannot be displayed

The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access. Please try the following:

Contact the Web site administrator if you believe that this request should be allowed. Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly. HTTP Error 405 - The HTTP verb used to access this page is not allowed. Internet Information Services (IIS)

Technical Information (for support personnel)

Go to Microsoft Product Support Services and perform a title search for the words HTTP and 405. Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Setting Application Mappings, Securing Your Site with Web Site Permissions, and About Custom Error Messages.

最佳答案

这似乎是 CURLOPT_POSTFIELDS 值的问题,它必须是一个键值 PHP 数组,如下所示:

$postFields = array(
    "FormData" => array(
        "Origin" => array(
        ...
        )
    )
);

更多信息:http://php.net/manual/en/function.curl-setopt.php

关于php - 使用 cURL 和 PHP 发送 POST 数据以检索航空公司信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21331675/

相关文章:

php - Mysqli增强的调试能力有哪些?

php - 使用 Active Record 类转义 codeigniter 进行 sql 注入(inject)

php - 使用 PHP mail() 发送多部分/替代

javascript - 使用 AJAX 编辑 JSON 文件

php - 我什么时候使用 PHP_EOL 而不是\n ,反之亦然? Ajax/Jquery 客户端问题

elasticsearch - Elasticsearch查询问题-[范围]格式错误的查询,预期[END_OBJECT],但发现[FIELD_NAME]

php - 如何从使用 header() 函数设置的错误代码服务器重定向到默认错误页面?

c# - 在默认浏览器中向自定义 URI 发送 POST 请求

php - 如何从 YouTube API 获取 YouTube 视频缩略图?

curl - 为什么这个 curl 命令在 groovy 中执行时会失败?