0
我一直在嘗試從PHP發送xml消息到asp,並使用CURL輸出對我的php頁面的響應,但沒有收到任何迴應。這是我曾嘗試過的:來自asp頁面的XML響應
<?php
$url = "https://someweb.asp";
$post_string = "xmlmessage=<?xml version='1.0' encoding='UTF-8'?>
<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;
?>
任何人都可以請指導我,我錯了嗎?
我試過你的代碼時得到這個:Warning:curl_setopt()[function.curl-setopt]:無效的curl配置選項第25行中的/home/add.php 錯誤的請求(無效的數字) – user994144
第25行:curl_setopt($ ch,CURLOPT_POST_FIELDS,array('xmlmessage'=> $ xml)); – user994144
抱歉,我的錯字。應該是CURLOPT_POSTFIELDS(只有一個'_') –