How to handle XML sent via POST?

I get XML sent via POST. Naturally, I need to parse this XML to get useful properties for me. However, when I get XML, it seems like PHP parses it as a query string.

For example, this xml:

<?xml version="1.0" encoding="utf-8"?>
<ForgotPassword>
    <version>1.0</version>
    <authentication>
        <login>myresllerid</login>
        <apikey>1234567890abcdef</apikey>
    </authentication>
    <parameters>
        <emailAddress>joesmith@example.com</emailAddress>
    </parameters>
</ForgotPassword>

It becomes (from print_r($_REQUEST)):

Array
(
    [
<?xml_version] => "1.0" encoding="utf-8"?>
<IDCForgotPassword>
    <version>1.0</version>
    <authentication>
        <login>myresllerid</login>
        <apikey>1234567890abcdef</apikey>
    </authentication>
    <parameters>
        <emailAddress>joesmith@example.com</emailAddress>
    </parameters>
</IDCForgotPassword>
)

You can see that XML is split into the first equal sign (=) in XML into a key / value pair.

How can I avoid this?

+3
source share
1 answer

If enctype is not multipart / form-data i>, use php: // input to get raw input.

$c = file_get_contents('php://input');
+5
source

Source: https://habr.com/ru/post/1744780/


All Articles