NSURLConnection 和 NSHTTPCookie
场景:验证用户身份。抓取cookie,为其他请求设置cookie。美好的。我无法立即弄清楚身份验证失败时如何处理而不将下一个视图推送到屏幕上。如果我的响应是 {errors:{password:do not match}} 我是否也应该解析此响应并相应地创建一个条件?我应该简单地检查响应代码吗?我看得出来,我让这件事变得很困难。我在以下位置添加了下一个视图:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
因此,当连接完成时,它自然会推送下一个视图。如果身份验证也失败,我想阻止它到达这里。也许我不应该从这里推动我的下一个观点。那去哪儿呢?
Scenario: Authenticating a user. Grab the cookie, set the cookie for other requests. Fine. What I can't immediately figure out is how to handle when the authentication fails without push my next view onto the screen. if my response is {errors:{password:does not match}} should i parse this response too and create a condition accordingly? Should I simply check the response code? I'm making this to difficult, I can tell. I added my next view in:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
so, when the connection finishes, it naturally pushes the next view. I'd like to prevent it from ever getting here if the authentication fails too. Maybe I shouldn't push my next view from here. Where then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我检查重定向路径:这会显示身份验证是否正常。
I check the redirect path: This shows me if the authentication went fine or not.
这样,它就永远不会到达connectionDidFinishLoading来推送下一个视图。
Rails 响应应该如下所示。
This way, it never gets to connectionDidFinishLoading to push the next view.
Rails response should look like this.