我正在设置信用卡处理程序,需要对CURL使用替代方法。当我使用测试服务器(未调用SSL URL)时,以下代码可以正常工作,但是现在当我在使用HTTPS的工作服务器上对其进行测试时,它失败,并显示错误消息“无法打开流”。
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包装器。
$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) {
[...]
}
关于php - 如何使file_get_contents()与HTTPS一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4858261/