我需要从使用带自签名证书的https的网站下载网站内容。浏览器具有功能"添加例外>获取证书>确认证书异常",我想在PHP中做同样的事情。所以我从Firefox导出了网站证书作为X509证书(* .PEM),我尝试了这个:
$arrContextOptions = array(
"ssl" => array(
"allow_self_signed" => TRUE,
"cafile" => 'cert-from-firefox.pem',
"verify_peer" => TRUE,
"verify_peer_name" => TRUE,
),
);
$content = file_get_contents('https://...', NULL, stream_context_create($arrContextOptions));
此脚本的结果是:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\...
Warning: file_get_contents(): Failed to enable crypto in C:\...
我可以做些什么来模拟浏览器的行为?