flask与http

flask与http

  1. URL组成
    http://www.example.com/hello?name=Jerry#comment

    协议: http
    主机:www.example.com
    请求资源path: /hello
    查询字符串:name=Jerry
    锚点: #comment

  2. 请求报文
    包括 请求方法,URL, 协议,头部信息,请求内容

请求方法

请求说明
PUT获取资源
POST创建或更新资源
PUT创建或替换资源
DELETE删除资源
HEAD获取头部信息
OPTIONS询问支持的方法

Requst对象

属性
path‘/hello’
full_path‘/hello?name=Jerry’
hostwww.example.com
host_url‘/http://www.example.com
base_urlhttp://www.example.com/hello
urlhttp://www.example.com/hello?name=Jerry
form获取表单提交数据
args获取查询字符串
files获取上传文件
  1. 请求处理
  • 路由匹配
    @app.route(’/hello’)
  • HTTP方法
    @app.route(’/hello’, methods=[‘GET’, ‘POST’])
  • url处理
    @app.route(’/hello/<int:year>’)
  1. http响应
  • 响应报文
    协议版本, 状态码,状态码, 原因短语, 响应头, 响应主体
  • flask响应对象
def index():
    res = make_response('首页', 200)
    res.headers['Content-type'] = 'text/plain;charset=utf-8'
    # res.mimetype = 'text/plain'
    return res
方法说明
headers头部信息
status状态码, 文本
status_code状态码
mimetypeMIME类型
set_cookie()设置一个cookie
  1. Cookie
    res.set_cookie(‘key’, ‘value’, ‘domain’, ‘path’, expires=datetime.now() + timedelta(minutes=10), httponly)
    读取
    request.cookies.get(‘name’, ‘None’)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值