我总是使用 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(
...
)
)
);
关于php - 使用 cURL 和 PHP 发送 POST 数据以检索航空公司信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21331675/