开发者

XML response on PHP [duplicate]

This question already has answers here: 开发者_运维问答 Closed 11 years ago.

Possible Duplicate:

XML response from asp page

I have been trying to send xml message from php to asp and output response to my php page using CURL but having no luck in receiving any response. This is what I have tried:

<?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;
?>

Can anyone please guide me where i am wrong?


try:

<?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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜