如何让 file_get_contents() 使用 HTTPS? [英] How to get file_get_contents() to work with HTTPS?
本文介绍了如何让 file_get_contents() 使用 HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在设置信用卡处理,需要使用 CURL 的解决方法.当我使用测试服务器(它没有调用 SSL URL)时,以下代码运行良好,但是现在当我使用 HTTPS 在工作服务器上测试它时,它失败并显示错误消息无法打开流".
I'm working on setting up credit card processing and needed to use a workaround for CURL. The following code worked fine when I was using the test server (which wasn't calling an SSL URL), but now when I am testing it on the working server with HTTPS, it's failing with the error message "failed to open stream".
function send($packet, $url) {
$ctx = stream_context_create(
array(
'http'=>array(
'header'=>"Content-type: application/x-www-form-urlencoded",
'method'=>'POST',
'content'=>$packet
)
)
);
return file_get_contents($url, 0, $ctx);
}
推荐答案
尝试以下脚本,看看是否有适用于您的 php 脚本的 https 包装器.
Try the following script to see if there is an https wrapper available for your php scripts.
$w = stream_get_wrappers();
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "
";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "
";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "
";
echo 'wrappers: ', var_export($w);
输出应该类似于
openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array(11) {
[...]
}
这篇关于如何让 file_get_contents() 使用 HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文