V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kingslanding
V2EX  ›  Node.js

superagent 的坑:各位是如何处理 redirect 的?

  •  
  •   kingslanding · 2018-08-17 08:13:33 +08:00 · 4354 次点击
    这是一个创建于 2050 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在爬一个网页,模拟登录,POST 后得到一个临时 cookie,再用这个临时 cookie 去访问重定向的网址,这个网址返回的 cookie 才是真正需要的 cookie.

    但 superagent 默认自动 redirect 时,不会带上临时 cookie,导致登陆失败. 如果用它的 redirects(0),来禁止重定向,又会抛出异常,程序又无法得到临时 cookie.

    有大佬知道怎么解决这个问题吗?

    beny2mor
        1
    beny2mor  
       2018-08-17 10:31:05 +08:00   ❤️ 1
    superagent.agent()无效吗?
    hanzichi
        2
    hanzichi  
       2018-08-17 10:34:23 +08:00   ❤️ 1
    不是很懂你的意思

    要不你直接用 `.agent()` 自动维护 cookie 试试

    理论上手动维护也是可行的
    kingslanding
        3
    kingslanding  
    OP
       2018-08-17 14:19:32 +08:00
    菜鸟感谢你们~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2937 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 15:16 · PVG 23:16 · LAX 08:16 · JFK 11:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.