2011-10-06 171 views
1

我必须从PHP向具有自签名证书的安全https服务器发出请求。我在cURL中有一个工作命令行,但有很多问题将它转换为正确和可用的PHP选项。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中的正确方法是一些提示?

回答

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'); 
+0

这是不行的,我觉得我缺少--key cert.key? – user982637

+0

阅读从PHP文档中的文章。我显示了代码从http://www.php.net/manual/ru/function.curl-setopt.php#84374 – TROODON

+0

你nedd创建一个“.pem”文件 – TROODON