V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
17681880207
V2EX  ›  问与答

关于 flutter 开发,后台登录接口设置 cookie 如何处理?

  •  
  •   17681880207 · Oct 9, 2023 · 927 views
    This topic created in 935 days ago, the information mentioned may be changed or developed.

    原本的接口都是服务于 web 端的。登录接口在成功后,后台直接设置了 cookie ,不需要前端做额外的处理(如果是 token 的方式的话,前端需要保存 token 到 localstorage 中),后续的业务请求会自动携带 cookie 到后台,进行权限校验来返回数据。

    现在用同一个接口在 flutter 上实现登录,但是登陆后,请问 flutter 该怎么处理这个 cookie 呀?因为后续的接口再发送的时候,无法和 web 浏览器一样,自动携带发送到后台。

    6 replies    2023-10-10 10:07:30 +08:00
    LLaMA2
        1
    LLaMA2  
       Oct 9, 2023
    牢牢地记住,

    请求 API 后返回的数据不是在响应头( response header )就是在响应体( response body )中。


    你这种后端 set_cookie 的数据必然是在响应头的 Set-Cookie 字段中,不信你可以用 web 访问,打开开发者模式看看。除非他是非标操作!
    sujin190
        4
    sujin190  
       Oct 9, 2023
    https://pub.dev/packages/cookie_jar

    https://pub.dev/packages/sweet_cookie_jar

    这不就是 cookie_jar 么,大部分 http 库都有这东西支持,和浏览器一样自动维护请求 cookie
    17681880207
        5
    17681880207  
    OP
       Oct 10, 2023
    @ye4tar 感谢大佬~
    17681880207
        6
    17681880207  
    OP
       Oct 10, 2023
    @itbeihe @sujin190 感谢大佬们!我这就去试试~😗
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2692 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:22 · PVG 21:22 · LAX 06:22 · JFK 09:22
    ♥ Do have faith in what you're doing.