【问题标题】:cURL HTTPS follow redirectioncURL HTTPS 跟随重定向
【发布时间】:2013-05-10 10:47:35
【问题描述】:

我用下面的代码在重定向之后获取一个 HTTP url,然后传回它所在的新页面 url。

// Follow URL
private function follow_url($url) {
    $options = array( 
        CURLOPT_RETURNTRANSFER => true,     // return web page 
        CURLOPT_HEADER         => true,    // return headers 
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects 
        CURLOPT_ENCODING       => "",       // handle all encodings 
        CURLOPT_USERAGENT      => "spider", // who am i 
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect 
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect 
        CURLOPT_TIMEOUT        => 120,      // timeout on response 
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 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 ); 

    $output = $header["url"];
    return $output;
} 

我现在正试图让它与 HTTPS 一起工作,但它没有跟随它在输入的 URL 处停止。

有什么办法可以解决这个问题吗?

【问题讨论】:

    标签: php curl


    【解决方案1】:

    添加以下选项:

    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_SSL_VERIFYPEER => false,
    

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 2012-01-05
      • 2020-04-15
      相关资源
      最近更新 更多