带有https主机的file_get_contents工作得很好,除了特定主机(来自某公司的测试api服务器 - ip白名单,不能给你测试URL).这排除了未加载https模块和其他初始设置错误.
我已经测试了多个PHP安装,全部是v5.3.3,32位,Debian 32位.
该请求适用于cURL,但仅限于设置curl_setopt($curl,
CURLOPT_SSL_VERIFYPEER, 0);.但是,设置verify_peer"=>falsefile_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));
Run Code Online (Sandbox Code Playgroud)
.
有没有人遇到过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));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22765 次 |
| 最近记录: |