无法通过https发送curl请求

时间:2018-11-07 07:32:14

标签: php ssl curl

大家好,无法通过https连接到远程服务器。

这是我的代码:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://remote_ip:9192/?doc");
curl_setopt($ch, CURLOPT_SSLCERT, $private_key);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $secret_word);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, '');
curl_setopt($ch, CURLOPT_CAINFO, getcwd().$server_key);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

$output = curl_exec($ch);
$res = curl_error($ch);
var_dump(openssl_get_cert_locations());
echo $res;

我收到下一个输出:

array (size=8)
  'default_cert_file' => string '/usr/lib/ssl/cert.pem' (length=21)
  'default_cert_file_env' => string 'SSL_CERT_FILE' (length=13)
  'default_cert_dir' => string '/usr/lib/ssl/certs' (length=18)
  'default_cert_dir_env' => string 'SSL_CERT_DIR' (length=12)
  'default_private_dir' => string '/usr/lib/ssl/private' (length=20)
  'default_default_cert_area' => string '/usr/lib/ssl' (length=12)
  'ini_cafile' => string '/srv/site/keys/mycert.pem' (length=31)
  'ini_capath' => string '' (length=0)
SSL certificate problem: unable to get local issuer certificate

我什至尝试将pem文件添加到php.ini配置:

  

curl.cainfo =“ / srv / site / keys / mycert.pem”   openssl.cafile =“ / srv / site / keys / mycert.pem”

如果我通过curl在终端中提出请求,则证书很好:

  

curl --noproxy“ *” –cacert mycert.pem --cert newfile.pem:密码-k   https://remote_ip:9192/?doc

我将收到来自远程服务器的文档。

我的php脚本有什么问题?

0 个答案:

没有答案