XML response from asp page(来自 asp 页面的 XML 响应)
本文介绍了来自 asp 页面的 XML 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试将 xml 消息从 php 发送到 asp,并使用 CURL 将响应输出到我的 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
";
$header = "Content-type: text/xml
";
$header .= "Content-length: ".strlen($post_string)."
";
$header .= "Content-transfer-encoding: text
";
$header .= "Connection: close
";
$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 .= "
". curl_error($ch);
}
else
{curl_close($ch);}
echo $output;
?>
谁能指导我哪里错了?
推荐答案
不要为简单的 POST 构建自定义请求.CURL 完全有能力在没有所有这些恶作剧的情况下发帖:
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 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:来自 asp 页面的 XML 响应


猜你喜欢
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01