我正在设置信用卡处理,需要使用CURL的变通方法。当我使用测试服务器(它没有调用SSL URL)时,下面的代码运行良好,但是现在当我使用HTTPS在工作服务器上测试它时,它失败了,并显示错误消息"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);
}
发布于 2009-12-30 01:58:23
尝试以下脚本,看看是否有适用于您的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) {
[...]
}
发布于 2016-08-02 20:25:59
$url= 'https://example.com';
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$response = file_get_contents($url, false, stream_context_create($arrContextOptions));
这将允许您从url获取内容,无论它是HTTPS。
发布于 2009-12-30 00:25:35
这可能是因为您的目标服务器没有有效的SSL证书。
https://stackoverflow.com/questions/1975461
复制相似问题