如何获取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', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_export($w);
输出应为
openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array(11) {
[...]
}
这篇关于如何获取file_get_contents()以使用HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文