php curl如何设置头部信息

  • 时间:
  • 来源:网络

   

php curl设置头部信息的方法:首先把自定义http头放入hearders array中;然后用“CURLOPT_HTTPHEADER”进行设置即可。

推荐:《PHP视频教程》

php curl设置自定义的HTTP头

把自定义http头放入hearders array, 然后用CURLOPT_HTTPHEADER设置。

$headers = array();
$headers[] = 'X-Apple-Tz: 0';
$headers[] = 'X-Apple-Store-Front: 143444,12';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: en-US,en;q=0.5';
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0';
$headers[] = 'X-MicrosoftAjax: Delta=true';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);