2011-10-14 42 views
0

可能重複:
XML response from asp pageXML響應

我一直在試圖從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; 
?> 

任何人都可以請指導我,我錯了嗎?

回答

1

嘗試:

<?php 
//do not put the $url within the XML (like in your original post) 
$url = "https://someweb.asp"; 

$post_string =<<<XML 
<?xml version='1.0' encoding='UTF-8'?> 
<abc> 
<UserId>123</UserId> 
</abc> 
XML; 

$post_string='xmlmessage='.rawurlencode($post_string); 
echo $post_string; 

/* 
//$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); 

//get rid of the following and use the POST headers  
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); 

//add the following two headers (for POST requests) 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_string); 

$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; 
?> 
+0

我得到的SSL連接如超時了。感謝您的幫助 – user994144

+0

我剛剛在SSL連接上測試了上面提供的代碼,它工作正常。也許,以下可能會有一些幫助:http://www.sitecrafting.com/blog/php-curl-ssl-connection-timeout/ – Hielo

+0

您是否添加了curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,0);你的代碼?我看到在http://stackoverflow.com/questions/7772146/xml-response-error你沒有使用該選項。 – Hielo