php - 带有 PHP CURL 的 SSL 证书

标签 php xml ssl curl

我正在使用 curl 通过 https 将 xml 文件发送到 rightmove API - 他们为我提供了所有证书。

我收到错误:

60SSL certificate problem: unable to get local issuer certificateResult =

我已经尝试了我在所有其他类似的 stackoverflow 帖子上找到的所有内容,但没有任何效果,我尝试下载旧的 cacert.pem 并更改 php.ini 中的文件 - 我安装了我的个人信息文件并在浏览器和本地机器,没有任何东西可以消除错误 60。

这是我的 PHP:

<?php
  $xml = file_get_contents("myxml.xml");

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__).'\mypem.pem');

  curl_setopt($ch, CURLOPT_URL, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);

  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($ch, CURLOPT_REFERER, 'https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_VERBOSE , 1);

  $ch_result = curl_exec($ch);
print curl_errno($ch);
print curl_error($ch);
  echo "Result = ".$ch_result;
  curl_close($ch);

?>

这让我苦恼了好几天,如果有任何帮助,我将不胜感激。

最佳答案

对于我的特殊情况,我需要添加 key 文件、sslcert 和证书密码。

   //$xml = file_get_contents("thexmlfile.xml");
  $xml= $propertyXml->asXML();
  $ch = curl_init();

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_CAINFO, getcwd() . '\pemfile.pem');

  curl_setopt($ch, CURLOPT_URL, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, getcwd() . '\myjks.jks');
  curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . '\pemfile.pem');
  curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "thesslpassword");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($ch, CURLOPT_REFERER, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_VERBOSE , 1);

 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  $ch_result = curl_exec($ch);
print curl_errno($ch);
print curl_error($ch);
  echo "Result = ".$ch_result;
  curl_close($ch);

关于php - 带有 PHP CURL 的 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36131857/

相关文章:

php - 如何在不在客户端系统上安装 xampp 的情况下运行 php 应用程序?

php - 通过 mysql 更新 PHP 中的表单

javascript - 来自 XML 的多段线

apache - 将所有流量重定向到 https ://www. 目前我有两个版本 http://www 和 https://www

java - 保护和验证使用 REST 的 iPhone 应用程序的最佳安全框架?

javascript - 如何使用JS使用更新值自动更新第二个文本框

php - 为 nginx 和 php-fpm 容器将 docker-compose 转换为 Kubernetes

C# 外部数据(类似于 iOS Plist)

xml - 使用 xmllint 提取最后一个子元素值

mysql - 为azure mysql提供sequelize安全连接