utf-8 url卷曲 [英] Utf-8 url get with curl

查看:96
本文介绍了utf-8 url卷曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用curl访问一些非拉丁字符的网址,问题是当我访问时我没有任何反应。我的浏览器访问它们没有问题,我检查了字符串转换,看来我正在访问
http://www.linkedin.com/pub/j-rgen-a-tr-ff/7/606 / 68a
而我的浏览器访问
http://se.linkedin.com/pub/j%C3%B6rgen-a-tr%C3%A4ff/7/606/68a
如何转换该字符串以使卷曲成功?

i am trying to visit some urls with non latin characters using curl, the problem is when i visit i get no response. My browser has no problem visiting them, i checked out the string transformations and it seems i am visiting "http://www.linkedin.com/pub/j-rgen-a-tr-ff/7/606/68a" while my browser visits "http://se.linkedin.com/pub/j%C3%B6rgen-a-tr%C3%A4ff/7/606/68a" How do i convert that string so the curl succeeds?

function hitFormGet($loginURL, $loginFields, $referer,$cookieString)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");

    //curl_setopt($ch,    CURLOPT_AUTOREFERER,         true);
    curl_setopt($ch,    CURLOPT_COOKIESESSION,         true);
    //curl_setopt( $ch, CURLOPT_COOKIE,$cookieString);
    curl_setopt($ch,    CURLOPT_FAILONERROR,         false);
    curl_setopt($ch,    CURLOPT_FOLLOWLOCATION,        false);
    curl_setopt($ch, CURLOPT_VERBOSE, 1 );
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate,sdch');
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch,    CURLOPT_FRESH_CONNECT,         true);
    curl_setopt($ch,    CURLOPT_HEADER,             false);
    //curl_setopt($ch,    CURLOPT_POST,                 true);
    curl_setopt($ch,    CURLOPT_RETURNTRANSFER,        true);
    curl_setopt($ch,    CURLOPT_CONNECTTIMEOUT,     30);
    curl_setopt($ch,    CURLOPT_USERAGENT, "Googlebot/2.1 (+http://www.googlebot.com/bot.html)");

    curl_setopt($ch, CURLOPT_URL, $loginURL.$loginFields);

    curl_setopt($ch, CURLOPT_REFERER, $referer);

    //curl_setopt($ch, CURLOPT_POSTFIELDS, $loginFields);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}


$res=hitFormGet("http://se.linkedin.com/pub/j%C3%B6rgen-a-tr%C3%A4ff/7/606/68a","","","");


推荐答案

您似乎正在从瑞典来。因此,您被重定向到se.linkedin.com。要按预期转换URL,您可以在动态url部分上应用urlencode(),如以下示例所示:j-rgen-a-tr-ff / 7/606 / 68a。

It looks like you are visiting linkedin from Sweden. That's why you are redirected to se.linkedin.com. To convert URL as expected you can apply urlencode() on your dynamic url part as in your example on: j-rgen-a-tr-ff/7/606/68a.

应该可以。

这篇关于utf-8 url卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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