file_get_contents忽略verify_peer => false? [英] file_get_contents ignoring verify_peer=>false?
问题描述
file_get_contents工作正常,除了特定主机(来自某公司的测试api服务器 - ip白名单,无法提供测试URL)。这排除了没有加载https模块和其他初始设置错误。
file_get_contents with https hosts works just fine, except for a particular host (test api server from some company - ip whitelisted, can't give you URL to test). This rules out not loaded https modules and other initial setup mistakes.
我已经测试了多个PHP安装,全部是v5.3.3,32位,Debian 32位。
I have tested with multiple PHP installations, all at v5.3.3, 32bits, Debian 32bits.
该请求适用于cURL,但仅限于设置 curl_setopt($ curl,
。但是,在file_get_contents的上下文中设置
CURLOPT_SSL_VERIFYPEER,0); verify_peer=> false
似乎没有任何区别。
The request works with cURL, but only if setting curl_setopt($curl,
CURLOPT_SSL_VERIFYPEER, 0);
. However, setting verify_peer"=>false
on the context for file_get_contents seems to make no difference.
使用file_get_contents ,完全相同的请求(相同的URL,相同的XML POST数据)失败, SSL:由同行重置连接:
With file_get_contents, the exact same request (same URL, same XML POST data) fails with SSL: Connection reset by peer:
$arrContextOptions=array(
"http" => array(
"method" => "POST",
"header" =>
"Content-Type: application/xml; charset=utf-8;\r\n".
"Connection: close\r\n",
"ignore_errors" => true,
"timeout" => (float)30.0,
"content" => $strRequestXML,
),
"ssl"=>array(
"allow_self_signed"=>true,
"verify_peer"=>false,
),
);
file_get_contents("https://somedomain:2000/abc/", false, stream_context_create($arrContextOptions));
。
有没有人加入用file_get_contents来解决这个问题? 任何想法如何调试?
Has anyone encountered this with file_get_contents? Any ideas how to debug?
推荐答案
试试这段代码:
$fp = fsockopen("ssl://somedomain/abc/", 2000 , $ErrNo, $ErrString, 30);
if (!$fp) {
echo "Error No : $ErrNo - $ErrString <br />\n";
} else {
$out = "POST / HTTP/1.1\r\n";
$out .= "Host: somedomain \r\n";
$out .= "Content-Type: application/xml; charset=utf-8;\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
如果你没有收到错误,我认为问题(带有file_get_contents)是从服务器配置生成客户端php配置。
if you don't get error , i think problem (with file_get_contents) is form client php configuration otherwise from server configuration.
这篇关于file_get_contents忽略verify_peer => false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!