doulian1852
doulian1852
2010-05-10 13:59
浏览 54

如何处理通过POST发送的XML?

I'm receiving XML sent via POST. Naturally I need to parse this XML to get at the goodies it holds for me. However, when I receive the XML is seems that PHP is parsing it like 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>

Becomes this (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 the XML is being broken up at the first equals sign (=) in the XML into a key/value pair.

How do I avoid this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douwen3973
    douwen3973 2010-05-10 14:07
    已采纳

    Unless enctype is multipart/form-data use php://input to fetch the raw input.

    $c = file_get_contents('php://input');
    
    点赞 评论

相关推荐