使用 AFNetworking的时候,如何管理 session ID
来源:互联网 发布:婚庆策划软件 编辑:程序博客网 时间:2024/04/29 06:51
问:
As the title implies, I am using AFNetworking in an iOS project in which the application talks to a server. When the user signs in, the server responds by sending back a success flag and the response headers contain the session ID.
I am wondering if AFNetworking automatically sends the session ID with every subsequent request or should I take care of this myself in some way?
For your information, I have no control over the back-end in terms of how requests are authenticated. I am only building a client that talks to the server.
答:
Yes, your session ID should be sent automatically once you are logged in, as long as the cookie does not expire before the next request is sent (important detail to be sure of).NSURLConnection
, which AFNetworking uses, takes care of the details for this for you.
On the backend AFNetworking is using NSURLConnection
which in turn automatically updatesNSHTTPCookieStorage
to store the session. You can manipulate or delete the cookies as you see fit by messing with the cookie storage.
Like if you wanted to appear to the service as not logged in, you could just delete the session cookie associated to that domain. Some services I have worked with will error if you are already logged in and attempt to login again. Additionally there was no way to check login status. Quick fix, get the cookies from URL and delete them :
- NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL: networkServerAddress];
- for (NSHTTPCookie *cookie in cookies)
- {
- [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
- }
- 使用 AFNetworking的时候,如何管理 session ID
- 使用 AFNetworking的时候,如何管理 session ID
- Session ID 是如何产生的?
- 在使用caffe的时候,如何设置GPU的ID号
- 如何管理hibernate的session
- 使用Session.Abandon()的时候要小心
- 禁用cookie的时候怎么使用session
- 如何获取当前的Oracle用户的session id
- 在幼儿园管理系统中使用BootStrap的时候,如何快速找到合适的图标!
- 如何取得Oracle当前会话的编号(Session ID)?
- Easyui解决使用tab的时候id冲突问题
- 使用AFNetworking上传图片操作的时候出现reason: 'Invalid parameter not satisfying: name’?
- AFNetworking的使用
- AFNetWorking的基本使用
- AFNetWorking 的简单使用
- AFNetworking 的使用
- AFNetworking的使用
- AFNetworking 的使用
- VC check box用法
- AOJ Problem NO.177~179 A+B problem
- 今天开始,成为一个认真的ACMer
- android studio shell 命令行自动打包(mac 平台)
- LeetCode 098 Validate Binary Search Tree
- 使用 AFNetworking的时候,如何管理 session ID
- Struts2中UI标签之表单标签介绍
- 【Java并发编程】之十二:线程间通信中notifyAll造成的早期通知问题(含代码)
- MVC学习最佳实践
- “读心术”或将代替传统密码:EEG识别脑电波,以此来鉴别身份
- java日期操作专题
- utunbu下transmission屏蔽v4流量
- js中变色小特效
- python 的 = 与 +=