Python 调用 HTTP API 接口模板
Created At :
Views 👀 :
搜索引擎上获取的代码大多鱼龙混杂,因此自己写一个保存以待后用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #!/usr/bin/env python # -*- coding:utf-8 -*- #@Time : 2021/8/9 20:30 #@Author: f #@File : main.py
import requests
def sendPost(param1,param2): base_url = 'http://url/' data ={ 'param1':param1, 'param2':param2 } headers = { 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)', 'Accept': 'text/html, application/xhtml+xml, */*'
} session = requests.session() response = session.post(base_url, data=data,headers=headers, verify=False) print(response.text) if __name__ == '__main__': param1='param1' param2='param2' sendPost(param1,param2)
|
转载无需注明来源,放弃所有权利