php-stream_context_create函数针对https请求处理

2021/8/6 1:35:51

本文主要是介绍php-stream_context_create函数针对https请求处理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

官方文档有很多例子
https://www.php.net/manual/zh/function.stream-context-create.php
但是有些旧了
当我在源码编译安装php的时候, 有脚本使用了这个函数进行https的时候报错了

Warning: fopen(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /mnt/software/php-src/pear/fetch.php on line 66

Warning: fopen(https://pear.php.net/install-pear-nozlib.phar): failed to open stream: No such file or directory in /mnt/software/php-src/pear/fetch.php on line 66`

当我查看php-src/pear/fetch.php脚本时,代码是这样的:

并没有https请求对安全认证做处理,导致无法访问链接
stackoverflow找了这个在请求头设置关闭证书的校验:
https://stackoverflow.com/questions/45273206/https-for-stream-context-create

    $copt = array(
        'http' => array(
            'proxy' => preg_replace('/^http/i', 'tcp', $_ENV['http_proxy']),
            'request_fulluri' => true,
        ),
        'ssl'  => [ // here comes the actual SSL part...
            'verify_peer'      => false,
            'verify_peer_name' => false,
        ]
    );

重新编译安装成功!


丝滑.....



这篇关于php-stream_context_create函数针对https请求处理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程