drqxfmfa804578 2012-05-01 08:36
浏览 101
已采纳

PHP - 使用cURL访问受HTTPS(SSL)保护的站点

The following code returns Exit code 58.

From cURL documentation: CURLE_SSL_CERTPROBLEM (58) problem with the local client certificate.

// create a new CURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . $CERT);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD,"XXXXX");

curl_setopt($ch, CURLOPT_SSLVERSION, 3);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content Type: text/xml',
    'User-Agent: XXXXX',
    'User-Name: XXXXX'
));

$RESPONSE = curl_exec($ch);  

var_dump($RESPONSE);

// close CURL resource, and free up system resources
curl_close($ch);

Is there something I'm missing?

  • 写回答

2条回答 默认 最新

  • dongyuying1507 2012-05-01 10:44
    关注

    Make sure the file in getcwd() . $CERT exists and is a valid PEM certificate. If it seems ok, set the following option to get more SSL certification details output to STDERR:

    curl_setopt($ch, CURLOPT_CERTINFO, true);
    

    Note that this setting only has effect if CURLOPT_VERBOSE is set to true, which you already have.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用