首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP CURL和HTTPS

PHP CURL和HTTPS
EN

Stack Overflow用户
提问于 2018-09-29 01:58:29
回答 2查看 0关注 0票数 0

我发现这个功能做了很棒的工作(恕我直言):http//nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl

代码语言:javascript
复制
/**
 * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
 * array containing the HTTP server response header fields and content.
 */
function get_web_page( $url )
{
    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't 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 );

    $header['errno']   = $err;
    $header['errmsg']  = $errmsg;
    $header['content'] = $content;
    return $header;
}

我唯一的问题是它不适用于https://。Anny想法我需要做些什么来使这个工作为https?谢谢!

EN

Stack Overflow用户

发布于 2018-09-29 11:54:08

我试图使用CURL用PHP做一些https API调用,并遇到了这个问题。我注意到php网站上的一个推荐让我启动并运行:http//php.net/manual/en/function.curl-setopt.php#110457

请大家,停止将CURLOPT_SSL_VERIFYPEER设置为false或0.如果您的PHP安装没有最新的CA根证书包,请在curl网站下载并将其保存在您的服务器上: http://curl.haxx.se/docs/caextract.html 然后在php.ini文件中设置一个路径,例如在Windows上: curl.cainfo = C:\ PHP中\ cacert.pem 关闭CURLOPT_SSL_VERIFYPEER允许中间人(MITM)攻击,这是你不想要的!

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档