2012-05-01 14:33
浏览 54

cURL SSL请求失败

I'm trying to work with Liveperson REST API, I use the following php code:

$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, "");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization: '.$authorization,'Accept: '.$accept,'Content-Type: '.$contentType));
$response = curl_getinfo( $ch );

The request fails, I already tried the following

  • enabeling openssl on php.ini
  • exporting the certificate from liveperson server and using it in my code
  • followed the instruction here

any help will be appreciated!

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用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”) ; | ncurl_setopt($ ch,CURLOPT_URL,“"); curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization:'.$ 授权,'接受:'。$ accept,'Content-Type:'。$ contentType)); curl_exec($ ch); $ response = curl_getinfo($ ch); var_export($ response); curl_close( $ ch);


  • 在php上启用openssl .ini
  • 从liveperson服务器导出证书并在我的代码中使用
  • ,然后按照这里


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsmupo6631 2012-05-01 14:45

    Try removing getcwd() from line 9 in your code. You are using fullpath "C:/dev/wamp/exported.crt", that is relative to your current working directory, this is wrong. :)

    Hope this solves it

    解决 无用
    打赏 举报
  • doukui9491 2012-05-01 14:50

    Remove CA certificate from your request:

    # 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). The certificate of Liveperson is definitely wrong.

    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.

    If the certification process is indeed responsible try to download [VeriSign's public root certificate] and use it as CAINFO:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_CAINFO, "C:/dev/wamp/verisign_root.crt");
    解决 无用
    打赏 举报

相关推荐 更多相似问题