以https主机的file_get_contents工作得很好,除了特定的主机(一些公司测试API服务器 - 的ip白名单,给不了你要测试的网址)。 这排除了未加载HTTPS模块等初始设置错误。
我曾与多个PHP的安装测试,所有在v5.3.3,32位,32位的Debian。
该请求可与卷曲,但只有当设置curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
。 但是,设置verify_peer"=>false
上的file_get_contents的背景下,似乎没有什么区别。
由对等连接复位:与的file_get_contents,完全相同的请求(相同的URL,相同的XML POST数据)失败,SSL:
$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遇到这个? 任何想法如何调试?
你错过了verify_peer_name
。 如果设置为false以及,请求工作:
$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,
"verify_peer_name"=>false,
),
);
file_get_contents("https://somedomain:2000/abc/", false, stream_context_create($arrContextOptions));
不”知道这是否会真正帮助,但不要尝试删除SSL
从你的选择阵列选项。
这背后的原因:根据http://www.php.net/manual/en/context.ssl.php , verify_peer
是false
默认。
allow_self_signed
REQUIRES verify_peer
,并且是false
默认。
从上面的,据我了解, allow_self_signed
可能覆盖您的设置verify_peer
。
所以,请不带任何选项尝试SSL
,或不allow_self_signed
,并让我们知道,如果,帮助任何。
你可以试着用调试这个Wireshark的 -你可能会得到什么不顺心一个更好的主意,你应该看到SSL错误发生。
试试这个代码:
$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配置,否则从服务器配置。
只有安装此
yum install ca-certificates.noarch