【问题标题】:cURL command line to PHPcURL 命令行到 PHP
【发布时间】:2011-10-06 17:12:31
【问题描述】:

我必须从 PHP 向具有自签名证书的安全 https 服务器发出请求。我在 cURL 中有一个可用的命令行,但在将其转换为正确且有效的 PHP 选项时遇到了很多问题。

有效的 cURL 命令是这样的:

curl --cacert cert.pem
     --key cert.key
     --cert cert.crt
     --header 'content-type: text/xml'
     -X POST
     --data @ftit-request.xml https://serverip/dip/DipWebservice > outputfile

谁能给我一些关于如何在 PHP 中正确使用它的提示?

【问题讨论】:

    标签: php curl ssl-certificate ssl


    【解决方案1】:

    http://php.net/manual/en/book.curl.php

    curl_setopt($ch, CURLOPT_VERBOSE, '1');
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
    curl_setopt($ch, CURLOPT_CAINFO,  getcwd().'/cert/ca.crt');
    curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'/cert/mycert.pem');
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'password');
    

    【讨论】:

    • 这不起作用,我想我错过了 --key cert.key ?
    • 阅读 php doc 中的文章。我显示来自php.net/manual/ru/function.curl-setopt.php#84374 的代码
    • 您需要创建一个“.pem”文件
    • 我需要将 .crt 和 .key 转换/加入到 .pem 文件中。 cat cert.crt cert.key > cert.pem。之后它就起作用了。
    猜你喜欢
    • 2013-04-18
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 2013-08-25
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多