本文介绍了从ASP页面的XML响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图使用curl,但其在接收到任何回应没有运气从PHP和ASP和输出响应发送XML消息,我的PHP页面。这是我曾尝试:

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

任何人都可以请指导我在哪里,我错了?

Can anyone please guide me where i am wrong?

推荐答案

不要搭建一个简单的POST自定义请求。卷曲完全有能力这样做后没有所有这些恶作剧的:

Don't build a custom request for a simple POST. CURL is perfectly capable of doing a post without all those shenanigans:

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

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('xmlmessage' => $xml));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);

$result = curl_exec($ch);
if ($result === FALSE) {
    die(curl_error($ch));
}

echo $result

这篇关于从ASP页面的XML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 08:43