使用 Python 发布 XML 文件 [英] Post XML file using Python

查看:29
本文介绍了使用 Python 发布 XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 新手,需要一些帮助.我的目标是将一些带有 post 请求的 XML 发送到 URL,这将触发正在发送的 SMS.

I'm new to Python and in need of some help. My aim is to send some XML with a post request to a URL, which is going to trigger a SMS being sent.

我有一个小的 XML 文档要发布到 URL.我可以在需要发布的 python 代码中引用我服务器上的 XML 文档,还是在实际的 python 代码中包含要发送的 XML 数据.任何人都可以帮我举个例子吗?

I have a small XML document that I want to post to the URL. Can I reference the XML document on my server in the python code that needs posting, or do I include the XML data to be sent in the actual python code. Can any help me out with an example?

推荐答案

如果您需要发送 XML,我建议您查看 请求.它允许您使用 POST 请求轻松发送数据.

If you need to send XML I would recommend that you take a look at requests. It allows you to easily send data using POST requests.

您应该能够使用请求直接从 Python 代码传输 XML 数据.

You should be able to transmit the XML data directly from your Python code using requests.

xml = """my xml"""
headers = {'Content-Type': 'application/xml'}
requests.post('http://www.my-website.net/xml', data=xml, headers=headers)

如果您不想对 xml 文档进行硬编码,您也可以从文本文件加载 xml 并发送.

You could also load the xml from a text-file and send that, if you don't want to have the xml document hard-coded.

这篇关于使用 Python 发布 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆