基于HTTP协议客户端和服务端传递信息通常会把具体的内容放在四个地方。
POST /test?x=valueX HTTP/1.1
Host: 127.0.0.1:5000
Content-Type: application/x-www-form-urlencoded
z: valueZ
Cache-Control: no-cache
Postman-Token: bb060ed5-783e-6470-05ee-f05a71df972c
y=valueY
from flask import request
@app.route('/test', methods=['GET', 'POST'])
def test():
# 获取 url 参数内容
x = request.args.get("x")
# 获取 form 表单内容
y = request.form.get("y")
# 获取 http 头部内容
z = request.headers.get("z")
print("x from url param: ", x)
print("y from form param: ", y)
print("z from headers: ", z)
return "test"
POST /test HTTP/1.1
Host: 127.0.0.1:5000
Content-Type: application/json
z: valueZ
Cache-Control: no-cache
Postman-Token: 2b3e8991-a48e-1653-c6e3-1b07d7411a29
{"url": "http://dig404.com"}
@app.route('/test', methods=['GET', 'POST'])
def test():
# 获取json格式的body,返回直接就是dict类型
content = request.get_json(silent=True)
content.get('url', None)
print(content)
return ""
如果喜欢,您就给个赞呗。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有