如何使file_get_content()与HTTPS一起工作?我正在设置信用卡处理,并需要使用一个解决办法的卷曲。当我使用测试服务器(它没有调用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);}
3 回答
![?](http://img1.sycdn.imooc.com/54586431000103bb02200220-100-100.jpg)
温温酱
TA贡献1752条经验 获得超4个赞
$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) { [...]}
![?](http://img1.sycdn.imooc.com/5333a01a0001ee5302000200-100-100.jpg)
浮云间
TA贡献1829条经验 获得超4个赞
这个 php_openssl
必须存在并启用扩展。 allow_url_fopen
必须设置为 on
extension=php_openssl.dll allow_url_fopen = On
![?](http://img1.sycdn.imooc.com/54584e1f0001bec502200220-100-100.jpg)
冉冉说
TA贡献1877条经验 获得超1个赞
function getSslPage($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); curl_close($ch); return $result;}
注意:这将禁用ssl验证,这意味着 HTTPS提供的安全性丢失了。..只使用此代码进行测试/本地开发, 从不上网或者其他面向公众的网络。如果此代码有效,则意味着SSL证书不受信任或无法验证,您应该将其作为一个单独的问题加以解决。
- 3 回答
- 0 关注
- 796 浏览
添加回答
举报
0/150
提交
取消