简体   繁体   English

cURL SSL 请求失败

[英]cURL SSL request fails

I'm trying to work with Liveperson REST API, I use the following php code:我正在尝试使用 Liveperson REST API,我使用以下 php 代码:

$authorization = "LivePerson appKey=MY_APP_KEY";
$accept = "application/xml";
$contentType = "application/xml";


$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "C:/dev/wamp/exported.crt");

curl_setopt($ch, CURLOPT_URL, "https://dev.liveperson.net/api/account/1234?v=1");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization: '.$authorization,'Accept: '.$accept,'Content-Type: '.$contentType));
curl_exec($ch);
$response = curl_getinfo( $ch );
var_export($response);
curl_close($ch);

The request fails, I already tried the following请求失败,我已经尝试了以下

  • enabeling openssl on php.ini在 php.ini 上启用 openssl
  • exporting the certificate from liveperson server and using it in my code从 liveperson 服务器导出证书并在我的代码中使用它
  • followed the instruction here按照此处的说明进行操作

any help will be appreciated!任何帮助将不胜感激!

Try removing getcwd() from line 9 in your code.尝试从代码的第 9 行中删除getcwd() You are using fullpath "C:/dev/wamp/exported.crt", that is relative to your current working directory, this is wrong.您使用的是相对于您当前工作目录的完整路径“C:/dev/wamp/exported.crt”,这是错误的。 :) :)

Hope this solves it希望这能解决它

Remove CA certificate from your request:从您的请求中删除 CA 证书:

# curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "C:/dev/wamp/exported.crt");

Actually you have to define here the public key/certificate file of the Certificate Authority (which is in your case VeriSign).实际上,您必须在此处定义证书颁发机构的公钥/证书文件(在您的情况下为 VeriSign)。 The certificate of Liveperson is definitely wrong. Liveperson的证书肯定是错误的。

Check if the certificate is responsible for your problems:检查证书是否对您的问题负责:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

This setting is of course no recommendation for your project but it might help to identify the problem.此设置当然不适合您的项目,但它可能有助于识别问题。 If the certification process is somehow responsible you should get a successful connection to the API host of Liveperson.如果认证过程以某种方式负责,您应该成功连接到 Liveperson 的 API 主机。

If the certification process is indeed responsible try to download [VeriSign's public root certificate] and use it as CAINFO:如果认证过程确实负责尝试下载[VeriSign的公共根证书]并将其用作CAINFO:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, "C:/dev/wamp/verisign_root.crt");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM