【发布时间】:2015-02-26 18:30:22
【问题描述】:
所以,我在 CLI 上尝试了这个 cURL,它可以工作,但在我的 PHP 脚本上却不行。
在我的 PHP 脚本中,它显示 {"staff":[],"reserved":[],"types":[]} 当 json 应该包含更具体的数据时。当我使用 cURL 和使用 file_get_contents 时都会发生这种情况。
当我通过浏览器打开它时,它也不起作用。它显示为空白。
请注意:我已经在 PHP 上使用 curl 创建了数百次网络爬虫,并且通常效果很好。
这是我在 CLI 上使用的 cURL:
curl "https://foodandfarmtour.theflybook.com/api/engine/_reservations/?id=FA860873-B947-4647-BF8C-2062628E09F9&from=2015-02-01&to=2015-03-05" -H "Cookie: PHPSESSID=f1dotub17jua33qhnoat71ddc5; fbe_aid=FA860873-B947-4647-BF8C-2062628E09F9; br_dft=m"%"2Fd"%"2FY" -H "Accept-Encoding: gzip, deflate, sdch" -H "Accept-Language: en-US,en;q=0.8,id;q=0.6,ms;q=0.4,jv;q=0.2" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36" -H "Accept: */*" -H "Referer: https://foodandfarmtour.theflybook.com/book/trip/fb/?id=9932552A-8FF9-4A22-827F-3AAD4F909625" -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive" --compressed -k
这是我使用的 PHP 脚本:
$id = $args[0];
$start = date('Y-m-01');
$ch = curl_init('https://foodandfarmtour.theflybook.com/api/engine/_reservations/?id='.$id.'&from='.
$start.'&to='.date('Y-m-d', strtotime($start.' +32 days')));
var_dump('https://foodandfarmtour.theflybook.com/api/engine/_reservations/?id='.$id.'&from='.
$start.'&to='.date('Y-m-d', strtotime($start.' +32 days')));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: */*",
// "Accept-Encoding:gzip, deflate, sdch",
"Accept-Language:en-US,en;q=0.8,id;q=0.6,ms;q=0.4,jv;q=0.2",
"Connection: keep-alive",
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36",
"X-Requested-With: XMLHttpRequest",
"Host: foodandfarmtour.theflybook.com",
"Referer: https://foodandfarmtour.theflybook.com/book/trip/fb/?id=9932552A-8FF9-4A22-827F-3AAD4F909625",
"Cookie: PHPSESSID=f1dotub17jua33qhnoat71ddc5; fbe_aid=FA860873-B947-4647-BF8C-2062628E09F9; br_dft=m%2Fd%2FY"));
var_dump(curl_exec($ch));
return;
【问题讨论】: