简体   繁体   English

如何在Python中通过HTTP请求发送XML?

[英]How to send XML through HTTP Request in Python?

import urllib2
request = urllib2.Request("URL HERE", data="<port>0</port>",
                     headers={'Content-Type': 'application/xml'})
u = urllib2.urlopen(request)
response = u.read()

I tried this but found out the XML is never getting to the server. 我尝试了此操作,但发现XML从未到达服务器。 I need the XML to get to the server at the same time the HTTP request does so the proper response is sent back. 我需要XML在HTTP请求执行的同时到达服务器,以便将正确的响应发送回去。

也许这就是您要查找的内容: http : //www.voidspace.org.uk/python/articles/urllib2.shtml#data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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