HTTPS和file_get_contents

时间:2015-03-31 21:40:49

标签: php https openssl file-get-contents

我正在尝试使用file_get_contents阅读提供一些JSON对象的远程网站。连接应该加密,所以我尝试使用HTTPS连接。

<?php

$arrContextOptions=array(
    "ssl"=>array(
        "cafile" => "api.crt",
        "verify_peer"=> true,
        "verify_peer_name"=> true
    ),
);

$context = stream_context_create($arrContextOptions);

$jsonObjects = file_get_contents('https://example.com', false, $context);

?>

但是,连接失败并出现以下错误:

PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112) in api-read.php on line 13
PHP Warning:  file_get_contents(): Failed to enable crypto in api-read.php on line 13
PHP Warning:  file_get_contents(https://example.com): failed to open stream: operation failed in api-read.php on line 13

到目前为止我发现的消息来源提到了不同的可能原因。

  • 使用错误的协议版本。 AFAIK您只能使用密码选项禁止某些协议。 PHP应该支持SSLv2,SSLv3和TLSv1.0,对吗?我在命令行上使用curl验证远程机器使用SSLv3接受连接。
  • CN不匹配证书中提到的CN是我要连接的IP地址。

到目前为止,我无法解决问题或找到任何有用的信息。我的想法已经不多了。有什么建议吗?

0 个答案:

没有答案