简体   繁体   中英

How to fetch POST request body in XML format as a dictionary in Flask hit through Postman?

I am new to Flask. How can I fetch POST request body sent in XML format (mimetype="application/xml") through Postman as a dictionary in Flask API?

curl --location --request POST 'http://127.0.0.1:5000/test/' \
--header 'Content-Type: application/xml' \
--data-raw '<?xml version="1.0" encoding="UTF-8" ?>
            <root>
                <name>Sam</name>
                <age>22</age>
            </root>'

Is there any method to do so, like we do in case of JSON using:

content = flask.request.get_json()

Or is it like that we can only send the POST request body in JSON format?

I have tried xmltodict but I am not able to fetch the XML in Flask through flask.request

content = xmltodict.parse(request.{what??})

Any resources regarding the same will be appreciated.

You can parse XML, if you send the XML as the value of a key in your POST request, eg POST Data is: xmldata="YOUR XML"

Read for more reference here: Flask Api to parse xml post requests returning errors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM