接受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

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2021-07-03
  • 2021-12-30
相关资源
相似解决方案