php curl模拟请求ajax
PHP 2014/11/26 23:51:19 点击:不统计
<本文原载于www.forasp.cn>
php在curl请求外部文件或者数据的时候发现外部url做了是否是ajax的判断,我们怎么模拟ajax请求呢。
在chrom或者其他浏览器中通过网络查看ajax请求发现了ajax请求是在header中设置了X-Requested-With:XMLHttpRequest的参数
看下图

所以我们php curl 模拟请求ajax时 也要设置对应的X-Requested-With:XMLHttpRequest 这样我们通过curl就能模拟ajax请求了
在curl中header设置如下:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept' => '*/*',
'Accept-Charset' => 'UTF-8,*;q=0.5',
'Accept-Encoding' => 'gzip,deflate,sdch',
'Accept-Language' => 'zh-CN,zh;q=0.8',
'Connection' => 'keep-alive',
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer' => 'http://www.forasp.cn/',
'X-Requested-With' => 'XMLHttpRequest',
));
这样我们curl 模拟请求ajax就可以了
<%77w%77%2Ef%6F%72p%73%70%2Ec%6E>
·上一篇:php正则替换一次 >> ·下一篇:php数组转换为xml >>