【问题标题】:Need to read an https web page but my web server dont support https wrapper需要阅读 https 网页,但我的网络服务器不支持 https 包装器
【发布时间】:2010-11-20 21:34:49
【问题描述】:

我需要通过这个简单的命令使用 php 读取网页的内容:

$pagina='https://graph.facebook.com/me?access_token=' . $cookie['access_token'];
$user = json_decode(file_get_contents($pagina));

如您所见,协议是 https。当我执行这个命令时,我总是得到:

[function.file-get-contents]:失败 打开流:

在 stackoverflow 的其他答案中,一些用户建议使用此代码:

$w = stream_get_wrappers();
echo 'openssl: ',  extension_loaded  ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_dump($w);

为了知道我的服务器有没有https wrapper,结果是No.

那么,我知道如何使用 php 检索这个 https 页面吗?也许与 CURL 任何示例代码?非常感谢!

【问题讨论】:

    标签: php curl https


    【解决方案1】:

    Https 网站使用 curl

    <?php
    $url = "https://www.google.com/";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "$url");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;
    ?>
    

    【讨论】:

    • 结果为空...并且带有 vardump bool(false)
    • 在 curl_exec 之后运行此代码 -> echo curl_error($ch);查看错误消息
    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多