cUrl集语言标题 [英] cUrl set language header

查看:245
本文介绍了cUrl集语言标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为我的cURL请求设置语言标题?例如现在我得到facebook.com的主页在荷兰语,可能是因为我的服务器是在荷兰/默认语言发送通过头像?



我喜欢英语前荷兰语这个case所以我试图设置一个httpheader在curl,但我没有意义?



(zend符号)

  CURLOPT_HTTPHEADER => 'Accept-Language:en-US; q = 0.6,en; q = 0.4',



解决方案

您必须在请求中添加标题选项。



你会有这样的:

  $ options = array(
CURLOPT_RETURNTRANSFER = // return web page
CURLOPT_HEADER => false,//不返回标题
CURLOPT_FOLLOWLOCATION => true,//跟随重定向
.....

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

所有你需要做的是将这一行添加到$ options数组:

  CURLOPT_HTTPHEADER => array(Accept-Language:en-US; q = 0.6,en; q = 0.4),

How can I set a language header for my cURL request? e.g. now I get the homepage of facebook.com in dutch, probably because my server is in the Netherlands / default language send by headers?..

I prefer english before dutch in this case so I tried to set an httpheader in curl but I make no sense? What do I do wrong or what should I have to set?

(zend notation)

CURLOPT_HTTPHEADER => 'Accept-Language: en-US;q=0.6,en;q=0.4',

Thanks in advance!

解决方案

You have to add a header option in your request.

You will have something like this:

$options = array(
    CURLOPT_RETURNTRANSFER => true,     // return web page
    CURLOPT_HEADER         => false,    // don't return headers
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
    .....

$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);

All you have to do is add this line to your $options array:

    CURLOPT_HTTPHEADER     => array("Accept-Language: en-US;q=0.6,en;q=0.4"),

这篇关于cUrl集语言标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆