WIwindson
V2EX  ›  问与答

REST Api 如何获取浏览器端的 token 呢?

  •  
  •   WIwindson · Jan 13, 2016 · 3619 views
    This topic created in 3957 days ago, the information mentioned may be changed or developed.

    使用的是 Django + Django Rest Framework TokenAuthentication ,有些地方不理解。
    网页端在使用 ajax post 请求的时候需要用到当前用户的 token ,但是 cookies 设置 httponly 了,如何获取 token 发送请求呢?
    还是说我一开始不把 token 放在 cookies ,而是使用 localStorage 存储起来?

    谢谢。

    2 replies  •  2016-01-13 15:40:36 +08:00
    WIwindson
    WIwindson
    OP
    Jan 13, 2016
    1
    xujif
    xujif
    Jan 13, 2016
    2
    web 端使用的时候不应该用 token ,而是使用 cookie 。
    一般情况下,可以用服务器端做一层 filter proxy ,在 filter 中根据 cookie 生成代理插入到请求头
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1173 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:59 · PVG 01:59 · LAX 09:59 · JFK 12:59
    ♥ Do have faith in what you're doing.