V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
sqbing
V2EX  ›  iDev

iOS 使用 ASI 模拟浏览器登陆失败 @Livid

  •  1
     
  •   sqbing ·
    sqbing · 2014-04-29 10:35:27 +08:00 · 3618 次点击
    这是一个创建于 3643 天前的主题,其中的信息可能已经有所发展或是发生改变。
    登陆代码如下:



    响应中没有出现名为auth的cookie。
    第 1 条附言  ·  2014-04-29 16:13:05 +08:00
    登陆流程和浏览器一样,先GET /signin获取once,再使用获取的once发送POST /signin
    10 条回复    2014-04-30 08:38:09 +08:00
    sobigfish
        1
    sobigfish  
       2014-04-29 10:58:43 +08:00
    =.= 我猜是useragent的问题
    dong3580
        2
    dong3580  
       2014-04-29 11:02:07 +08:00
    @sobigfish
    同样的问题,我用IE7的user-agent模拟会出问题,但是改成N8的user-agent就正确了...
    诶,顿时丧失兴趣了。
    sqbing
        3
    sqbing  
    OP
       2014-04-29 11:10:18 +08:00
    不行,已修改UA为
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36

    https://gist.github.com/sqbing/11389166
    sogood
        4
    sogood  
       2014-04-29 13:08:24 +08:00
    once 该和 cookie 里面的 PB3_SESSION 绑定,把这个传过去试试。
    sqbing
        5
    sqbing  
    OP
       2014-04-29 14:37:28 +08:00
    @sogood 刚检查了requestCookies,包含三个cookie字段,PB3_SESSION、V2EX_LANG、V2EX_TAB
    187j3x1
        6
    187j3x1  
       2014-04-29 15:27:32 +08:00
    once防csrf 每次访问动态生成 你得把它提取出来
    sqbing
        7
    sqbing  
    OP
       2014-04-29 16:12:06 +08:00
    @187j3x1 我没有固定once,我会每次先GET /signin,然后解析出once,再POST /signin
    hoogle
        8
    hoogle  
       2014-04-30 06:31:43 +08:00
    我用的AFNetworking,试试加入这个Header:

    [requestSerializer setValue:@"http://v2ex.com/signin" forHTTPHeaderField:@"Referer"];

    另推荐看下@WildCat @kyze8439690 两位童鞋的github。。
    WildCat
        9
    WildCat  
       2014-04-30 07:33:19 +08:00 via iPhone
    @hoogle 对,好像是需要Refer的
    sqbing
        10
    sqbing  
    OP
       2014-04-30 08:38:09 +08:00
    @WildCat @hoogle 感谢,确实是Referer字段的问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2854 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 11:23 · PVG 19:23 · LAX 04:23 · JFK 07:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.