Home > Backend Development > PHP Problem > What should I do if php cannot receive xml data?

What should I do if php cannot receive xml data?

藏色散人
Release: 2023-03-17 08:44:01
Original
1304 people have browsed it

Solution to the problem that php cannot receive xml data: 1. Use the "file_get_contents('php://input');" method to receive xml data; 2. Use "simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA'] , 'SimpleXMLElement', LIBXML_NOCDATA);" method to receive xml data.

What should I do if php cannot receive xml data?

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if php cannot receive xml data?

About some issues with php accepting xml, simplexml_load_string cannot receive data

These two methods are generally used to accept xml data

Method 1:

file_get_contents('php://input');
Copy after login

Method 2:

simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA'], 'SimpleXMLElement', LIBXML_NOCDATA);
Copy after login

It is recommended to use method 1, method 2 has been discarded in higher PHP versions

----------------- -------Good-looking dividing line------------------

Foreword: The company's projects are somewhat old, and they all use method 2.

Problem: When I use curl to request an interface written by others, method 2 cannot receive it, but method 1 can.

Solution: After testing, the Content-Type in the cur parameter that needs to be set is text/xml

Code: curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/ xml; charset=utf-8"));

The default value of Content-Type in PHP's cur parameter is application/x-www-form-urlencoded, tmd! Using method 2 will determine the Content-Type of the http request header

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php cannot receive xml data?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
objective-c - socket sends data in xml format
From 1970-01-01 08:00:00
0
0
0
How to parse and process HTML/XML in PHP?
From 1970-01-01 08:00:00
0
0
0
How to parse and process HTML/XML in PHP?
From 1970-01-01 08:00:00
0
0
0
How to parse and process HTML/XML using PHP?
From 1970-01-01 08:00:00
0
0
0
Update xml namespace with data from PHP form
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template