How to POST an xml element in python

前端 未结 3 1937
说谎
说谎 2021-02-01 08:32

Basically I have this xml element (xml.etree.ElementTree) and I want to POST it to a url. Currently I\'m doing something like

xml_string = xml.etree.ElementTree         


        
3条回答
  •  别那么骄傲
    2021-02-01 09:18

    If this is your own API, I would consider POSTing as application/xml. The default is application/x-www-form-urlencoded, which is meant for HTML form data, not a single XML document.

    req = urllib2.Request(url=url, 
                          data=xml_string, 
                          headers={'Content-Type': 'application/xml'})
    urllib2.urlopen(req)
    

提交回复
热议问题