我需要执行获取请求并随之发送标头。我可以用什么来做到这一点?
我需要设置的主要标头是浏览器标头。是否有捷径可寻?
如果您使用 cURL,则可以使用curl_setopt ($handle, CURLOPT_USERAGENT, 'browser description')
定义请求的用户代理标头。
如果您正在使用file_get_contents
,查看手册页上示例的调整文件获取内容 http://php.net/manual/en/function.file-get-contents.php:
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" .
"User-agent: BROWSER-DESCRIPTION-HERE\r\n"
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)