从具有自签名证书的站点获取网站内容(file_get_contents())

时间:2015-10-28 21:15:53

标签: php ssl https ssl-certificate

我需要从使用带自签名证书的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:\...

我可以做些什么来模拟浏览器的行为?

0 个答案:

没有答案