0
点赞
收藏
分享

微信扫一扫

【Python】requests发送http请求

小禹说财 2022-03-12 阅读 62

0 安装库+引用库

安装代码

pip install requests

引用库

import requests # http请求
import json # json数据格式

1 发送 http请求

# 需要发送http请求的url地址
url = "https://xxx.xxx.xxx" 
# 设置header
headers = {'content-type': "application/json"} 
# json数据
body = {"a":"a","b":"b"} 
# 发送请求
response = requests.post(url, data = json.dumps(body), headers = headers)
	

2 读取 http response

# 文本化返回值
response_msg = response.text
举报

相关推荐

0 条评论