我寫了一個類/函數通過PHP4/cURL通過https發送xml,只是想知道這是否是正確的方法,或者是否有更好的方法。PHP4:通過cURL通過HTTPS/POST發送XML?
請注意,PHP5目前不是一個選項。
/**
* Send XML via http(s) post
*
* curl --header "Content-Type: text/xml" --data "<?xml version="1.0"?>...." http://www.foo.com/
*
*/
function sendXmlOverPost($url, $xml) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// For xml, change the content-type.
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned
if(CurlHelper::checkHttpsURL($url)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
// Send to remote and return data to caller.
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
乾杯!
哇,不是目前的選擇嗎? :(另外,如果你沒有設置cURL,看看HTTP_Request(http://pear.php.net/package/HTTP_Request) – Till 2008-10-27 03:21:52