php接收不到xml数据的解决办法:1、使用“file_get_contents('php://input');”方法接收xml数据;2、使用“simplexml_load_string($globals['http_raw_post_data'], 'simplexmlelement', libxml_nocdata);”方法接收xml数据即可。
本教程操作环境:windows7系统、php8.1版、dell g3电脑。
php接收不到xml数据怎么办?
关于php接受xml的一些问题,simplexml_load_string收不到数据
接受xml数据一般使用这两种方法
方法1:
file_get_contents('php://input');
方法2:
simplexml_load_string($globals['http_raw_post_data'], 'simplexmlelement', libxml_nocdata);
建议使用方法1,方法2在php版本高的已经丢弃
------------------------好看的分割线------------------
前言:公司的项目有些久远,都是用的方法2。
问题:我在使用curl去请求其他人写的接口的时候,方法2接收不到,方法1可以。
解决办法:经过测试,需要设置的cur参数中的content-type为text/xml
代码:curl_setopt($curl, curlopt_httpheader, array(content-type:text/xml; charset=utf-8));
php的cur参数中的content-type默认值是application/x-www-form-urlencoded,tmd!使用方法2会判断http请求头的content-type
推荐学习:《php视频教程》
以上就是php接收不到xml数据怎么办的详细内容。