我有 2 个 php 脚本,用于发送一个 xml 文件并捕获它。我正在使用 cURL,一切正常。现在我正在尝试做同样的事情,但使用 HTTP over SSL (HTTPS)。我已经用 XAMPP 安装了本地服务器,并且我已经按照这篇文章设置了 SSL:在本地 xampp/apache 服务器上设置 SSL。
我正在尝试像这样发送 xml 文件:
<?php
/*
* XML Sender/Client.
*/
// Get our XML. You can declare it here or even load a file.
$xml = file_get_contents("data.xml");
// We send XML via CURL using POST with a http header of text/xml.
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");
//i use this line only for debugging through fiddler. Must delete after done with debugging.
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://ipv4.fiddler/iPM/receiver.php");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, 'https://ipv4.fiddler/iPM/receiver.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
echo "Result = ".$ch_result;
curl_close($ch);
// Print CURL result.
?>
我从这里下载了 cURL 的新证书:
http://curl.haxx.se/ca/cacert.pem
我不确定我应该把证书放在哪里,但我把它放在我这个项目的工作区目录中。
现在的问题是 XML 文件永远不会发送到接收方。有任何想法吗?