php curl设置自定义的HTTP请求头

 
更多

通过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);
打赏

本文固定链接: https://www.cxy163.net/archives/3447 | 绝缘体

该日志由 绝缘体.. 于 2018年04月20日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: php curl设置自定义的HTTP请求头 | 绝缘体
关键字: , , , ,

php curl设置自定义的HTTP请求头:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter