Python+requests库发送接口入参为xml格式的接口请求
2020-05-22 11:32
169 查看
钉钉、微博极速扩容黑科技,点击观看阿里云弹性计算年度发布会!>>>
一)接口入参准备:
url地址:http://httpbin.org/post
入参:
<?xml version="1.0" encoding = "UTF-8"?> <COM> <REQ name="多测师_王sir"> <USER_ID>duoceshi</USER_ID> <COMMODITY_ID>123456</COMMODITY_ID> <SESSION_ID>DwO68dQFBg9xIizKsC6RhaeHRxqIT9nmU</SESSION_ID> </REQ> </COM>
二)把上面入参内容保存放入到duoceshi.xml文件中:
三)发送接口请求:
#coding=utf-8 ''' python处理xml格式入参的接口 ''' #1.先把xml入参用open函数读出来变为字符串 def read_xml(): ''' 读取xml文件 :return: ''' f = open('duoceshi.xml',"r") body = f.read() #print(body) return body #2.发送接口请求 import requests class Api_Test(object): def send_post(self): url = "http://httpbin.org/post" r = requests.post(url, data=read_xml()) print(r.text) if __name__ == '__main__': api = Api_Test() #创建对象 api.send_post() #调用实例方法
四)查看响应体的内容:
{ "args": {}, "data": "<?xml version=\"1.0\" encoding = \"UTF-8\"?>\n <COM>\n <REQ name=\"\u591a\u6d4b\u5e08_\u738bsir\">\n <USER_ID>duoceshi</USER_ID>\n <COMMODITY_ID>123456</COMMODITY_ID>\n <SESSION_ID>DwO68dQFBg9xIizKsC6RhaeHRxqIT9nmU</SESSION_ID>\n </REQ>\n </COM>\n\n\n", "files": {}, "form": {}, "headers": { "Accept": "*/*", "Accept-Encoding": "gzip, deflate", "Content-Length": "248", "Host": "httpbin.org", "User-Agent": "python-requests/2.22.0", "X-Amzn-Trace-Id": "Root=1-5eb7ea8e-2b31c719d1ecd8f197e39c12" }, "json": null, "origin": "222.65.223.177", "url": "http://httpbin.org/post" }
原文链接:https://www.cnblogs.com/xiaoshubass/p/12864757.html
相关文章推荐
- Python+requests库发送接口入参为xml格式的接口请求
- python接口自动化发送get请求 详解(一)
- python接口自动化(六)--发送get请求接口(详解)
- 2.python接口自动化发送post请求上传文件
- python通过http请求发送soap报文进行webservice接口调用
- python接口自动化(八)--发送post请求的接口(详解)
- python调用java接口发送post请求
- python接口自动化1-发送get请求
- python接口自动化2-发送post请求
- python:post接口、发送multipart/form-data格式请求
- 【转】 python socket向百度发送http长连接请求 并做搜索
- 使用HttpRequester发送json请求测试接口
- python 发送http请求填坑
- 对于java用发送http请求,请求内容为xml格式
- python发送http请求之requests模块
- python socket向百度发送http长连接请求 并做搜索
- python 爬虫1:发送请求
- Python中通过requests模块发送POST请求.