一、接收xml数据, 使用php://input,代码如下:
<?php
$xmldata=file_get_contents("php://input");
$data=simplexml_load_string($xmldata);
print_r($data);
?>二、使用CURL发送xml数据,代码如下:
<?php
$xml = file_get_contents('1.xml');
$url = "http://test.xxx.com/xxx.php";
$header[]="Content-type: text/xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
curl_close($ch);
?>?>
本文介绍如何使用PHP进行XML数据的接收与发送。首先演示了如何通过php://input获取POST请求中的XML数据,并利用simplexml_load_string解析。接着展示了如何使用CURL发送XML数据到指定URL。适用于希望了解PHP中XML数据交互的开发者。
835

被折叠的 条评论
为什么被折叠?



