CURLOPT_HTTPHEADER的Accept-Language不起作用

时间:2016-08-23 18:53:53

标签: php curl http-accept-language

  

cUrl set language header

我试图通过使用cURL来获取Facebook主页的源代码,但由于我的服务器主机的位置,它全部都是中文。出于这个原因,我添加了Accept-Language CURLOPT_HTTPHEADER来将语言更改为英语,但失败了。根据我上面引用的答案,下面是我试过的cURL的PHP​​代码:

<?php

$url = "http://www.facebook.com/";

if(isset($_SERVER['HTTP_USER_AGENT']))
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
else
    $user_agent = "";

$options = array(
    CURLOPT_RETURNTRANSFER => true,     // return web page
    CURLOPT_HEADER         => false,    // don't return headers
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
    CURLOPT_HTTPHEADER     => array("Accept-Language: en-US;q=0.6,en;q=0.4"),
    CURLOPT_USERAGENT      => $user_agent);

$ch      = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err     = curl_errno($ch);
$errmsg  = curl_error($ch);
$header  = curl_getinfo($ch);
curl_close($ch);

echo $content;

?>

但它仍显示中文:

The Facebook was all Chinese.

我该如何解决这个问题?

0 个答案:

没有答案