我正在为下面的 curl 命令寻找 Python 等效项。
curl http://localhost/x/y/update -H 'Content-type: text/xml; charset=utf-8' --data-binary @filename.xml
顺便说一句,我通常使用下面的代码将数据作为字符串发布。
curl http://localhost/x/y/update --data '<data>the data is here</data>' -H 'Content-type:text/xml; charset=utf-8'
baseurl = http://localhost/x/y
thedata = '<data>the data is here</data>'
headers = {"Content-type": "text/xml", "charset": "utf-8"}
thequery = urlparse.urljoin(baseurl, thedata, querycontext)
therequest = urllib2.Request(thequery, headers)
theresponse = urllib2.urlopen(therequest)