|
通过curl模拟http请求的时候,如果希望服务器返回正确的文档类型和文档语言设置,就需要在请求里面带上 header 头信息了。这里记录一下php curl 带着请求头模拟访问网页的方法。
- $headers = array();
- $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
- $headers[] = 'Accept-Language: zh-CN,zh;q=0.8';
- $headers[] = 'Cache-Control: no-cache';
- $headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0';
- $headers[] = 'X-MicrosoftAjax: Delta=true';
复制代码 然后通过 CURLOPT_HTTPHEADER 进行设置,例如:
- <?php
- $ch =curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://www.phpernote.com/admin/manage.php');
- ......
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- ......
- $content = curl_exec($ch);
复制代码
|
|