python requests以json传参的形式请求数据实例

python requests以json传参的形式请求数据实例, python - requests请求数据,调用api, post方式且传参数以json方式,使用记录
import requests
import json
url = "https://www.hao366.net"
payload = json.dumps({
"name": "zhangsan"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print response.text对方接收时使用方法:
# 引用flask库
from flask import Flask,request
app= Flask (__name__)
@ app .route ('/abc',methods =['post'])
def abc():
data=request.get_json()
if data:
u=data.get('u')
if __ name__ = = "__main__":
app.run(debug=True)
# os . syst em (f'gunicorn -w 1 -b 0.0.0.0:10 filename:app')一发一收,收放自如。



















