簡體   English   中英

Utf-8網址卷曲

[英]Utf-8 url get with curl

我正在嘗試使用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”如何轉換該字符串,以便卷曲成功?

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","","","");

您好像正在訪問瑞典的linkedin。 這就是您被重定向到se.linkedin.com的原因。 要按預期轉換URL,您可以在動態網址部分上應用urlencode(),如下例所示:j-rgen-a-tr-ff / 7/606 / 68a。

它應該工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM