pythonrequests库api_Python+requests库发送接⼝⼊参为
xml。。。
⼀)接⼝⼊参准备:
⼊参:
<?xml version="1.0" encoding = "UTF-8"?>
duoceshi
123456
DwO68dQFBg9xIizKsC6RhaeHRxqIT9nmU
⼆)把上⾯⼊参内容保存放⼊到l⽂件中:
三)发送接⼝请求:
python处理xml文件#coding=utf-8
'''
python处理xml格式⼊参的接⼝
'''
#1.先把xml⼊参⽤open函数读出来变为字符串
def read_xml():
'''
读取xml⽂件
:return:
'''
f = open('l',"r")
body = f.read()
#print(body)
return body
#2.发送接⼝请求
import requests
class Api_Test(object):
def send_post(self):
url = "/post"
r = requests.post(url, data=read_xml())
)
if __name__ == '__main__':
api = Api_Test() #创建对象
api.send_post() #调⽤实例⽅法
四)查看响应体的内容:
{
"args": {},
"data": "<?xml version=\"1.0\" encoding = \"UTF-8\"?>\n \n \n duoceshi\n 123456\n DwO68dQFBg9xIizKsC6RhaeHRxqIT9nmU\n \n
\n\n\n",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "248",
"Host": "",
"User-Agent": "python-requests/2.22.0",
"X-Amzn-Trace-Id": "Root=1-5eb7ea8e-2b31c719d1ecd8f197e39c12"
},
"json": null,
"origin": "222.65.223.177",
"url": "/post"
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论