如何使用请求库发送xml正文?

如何使用请求库发送xml正文?,第1张

如何使用请求库发送xml正文?

只需直接发送xml字节即可

#!/usr/bin/env python2# -*- coding: utf-8 -*-import requestsxml = """<?xml version='1.0' encoding='utf-8'?><a>б</a>"""headers = {'Content-Type': 'application/xml'} # set what your server acceptsprint requests.post('http://httpbin.org/post', data=xml, headers=headers).text
输出量
{  "origin": "x.x.x.x",  "files": {},  "form": {},  "url": "http://httpbin.org/post",  "args": {},  "headers": {    "Content-Length": "48",    "Accept-Encoding": "identity, deflate, compress, gzip",    "Connection": "keep-alive",    "Accept": "*/*",    "User-Agent": "python-requests/0.13.9 CPython/2.7.3 Linux/3.2.0-30-generic",    "Host": "httpbin.org",    "Content-Type": "application/xml"  },  "json": null,  "data": "<?xml version='1.0' encoding='utf-8'?>n<a>u0431</a>"}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5646636.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存