0
我一直在試圖從PHP發送XML消息,ASP和使用捲曲我的PHP頁面輸出響應,但有沒有運氣在接收任何答覆。這是我已經嘗試過:
<?php
$post_string = "xmlmessage=<?xml version='1.0' encoding='UTF-8'?>
$url = "https://someweb.asp";
<abc>
<UserId>123</UserId>
</abc>";
//$header = "POST HTTPS/1.0 \r\n";
$header = "Content-type: text/xml \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
$header .= "Connection: close \r\n\r\n";
$header .= $post_string;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
if ($output == false || $info['http_code'] != 200) {
$output = "No cURL data returned for $url [". $info['http_code']. "]";
if (curl_error($ch))
$output .= "\n". curl_error($ch);
}
else
{curl_close($ch);}
echo $output;
?>
任何人都可以請指導我,我錯了嗎?
我得到的SSL連接如超時了。感謝您的幫助 – user994144
我剛剛在SSL連接上測試了上面提供的代碼,它工作正常。也許,以下可能會有一些幫助:http://www.sitecrafting.com/blog/php-curl-ssl-connection-timeout/ – Hielo
您是否添加了curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,0);你的代碼?我看到在http://stackoverflow.com/questions/7772146/xml-response-error你沒有使用該選項。 – Hielo