PHP 上的 XML 响应

发布于 2024-12-10 02:42:54 字数 1261 浏览 0 评论 0原文

可能的重复:
来自 asp 页面的 XML 响应

我一直在尝试将xml消息从php发送到asp并且使用 CURL 将响应输出到我的 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;
?>

任何人都可以指导我哪里错了吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携余温的黄昏 2024-12-17 02:42:54

尝试:

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

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;
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文