dongyun9120 2013-01-11 13:21
浏览 11

允许HTTPS包装器的自签名证书

Basically i have this:

function request($url) {
    return file_get_contents($url, false, stream_context_create(array(
        "ssl" => array(
            "verify_peer" => true,
            "allow_self_signed" => false,
        )
    )));
}

request("https://[A]");
request("https://[B]");

Where [A] is some URL on a server with a "real" certificate and [B] is something on one with only a self-signed certificate.

With [A] it works fine, with [B] i get this:

file_get_contents(): Failed to enable crypto

Which is a rather unfortunate error message that should have been something like "server certificate verification failed", but fine...

Now i thought: "ok, [B] is my test system - i don't care for the certificate" and changed the context into this:

"verify_peer" => false,
"allow_self_signed" => true,

It should now accept any server certificate, even my self signed one. But it's still the same behavior - [A] works, [B] doesn't. Why?


Btw: I know that it works well with the curl extension, but i want to beat this without it.

  • 写回答

2条回答 默认 最新

  • dou11655853 2014-12-02 02:00
    关注
    $contextOptions = [
        'ssl' => [
            'verify_peer' => false,
            'allow_self_signed' => true
        ]
    ];
    
    $sslContext = stream_context_create($contextOptions);
    
    file_get_contents("https://website.com/", false, $sslContext);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了