java+httpclient—— 一个简单的get请求——python的flask服务器——cookie设置以及后续访问返回——request上下文...

本文介绍了如何使用Python Flask框架设置cookie,并在两次请求中操作和读取cookie,展示了基本的会话管理。

python服务器:

from flask import Flask,request,make_response

app = Flask(__name__)


@app.route('/')
def index():

    resp = make_response("123456abc")

    resp.set_cookie("001a","001b")
    resp.set_cookie("002c","002d",max_age=500)


    print(request.headers)
    print('-----------------------------------------------------------------')
    print(request.cookies)
    print('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
    return resp



@app.route('/001')
def index01():

    resp = make_response("123")

    print(request.headers.get("Host"))
    print(request.headers)
    print('-----------------------------------------------------------------')
    print(request.cookies)
    print('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
    print(request.cookies.get("001a"))
print(request.cookies.get("002c"))
return resp if __name__ == '__main__': app.run(debug=True)

web第一次访问:

web第一次访问,python打印:

web第二次访问:

web第二次访问,python打印:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值