更换函数file_get_contents验证ssl的写法 phpnamespace appindexcontroller;use thinkController;use thinkDb;use thinkRequest;use payepay;class Index extends Controller public function _initialize $webname=Dbnam
更换函数file_get_contents验证ssl的写法:
-
使用curl函数代替file_get_contents函数,curl函数默认支持https协议。
-
在curl函数中添加CURLOPT_SSL_VERIFYHOST和CURLOPT_SSL_VERIFYPEER参数,设置为false,表示不验证SSL证书。
修改后的代码如下:
$url1="https://www.example.com/api"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch);
原文地址: https://www.cveoy.top/t/topic/hqx0 著作权归作者所有。请勿转载和采集!