PHP接收和发送XML数据(json也通用)
2024-10-19 00:33:58
一、接收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); ?>
转:https://blog.csdn.net/wclovesjl/article/details/10348727
最新文章
- MySQL数据库备份--mysqldump用法
- 菜鸟学Windows Phone 8开发(3)——布局和事件基础
- 对于Maven管理的项目制定虚拟目录
- PHP编译安装出错configure: error: mcrypt.h not found. Please reinstall libmcrypt的解决办法
- Android 模仿QQ空间风格的 UI(转)
- C#编码标准--编码习惯
- cocos2d-x游戏开发系列教程-坦克大战游戏之敌方坦克AI的编写
- 脱壳第二讲,手动脱壳PECompact 2.x
- HTTPS加密原理
- 查找运行时间超过1天的frmweb进程
- C++设计实现一个不能被继承的类
- LeetCode: String to Integer (atoi) 解题报告
- PostgreSQL ALTER TABLE中改变数据类型时USING的用法<;转>;
- MySQL Disk--NAND Flash原理
- PHP简单工厂模式、工厂方法模式和抽象工厂模式
- And Design:拓荒笔记——Form表单
- spring中的default-lazy-init参数和lazy-init
- python基础----多态与多态性、super函数用法、继承原理
- coding.net--多人合作开发git的使用
- 统计tophat map上的read数量