使用 AFNetworking的时候,怎样管理 session ID
问:
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的更多相关文章
- nodejs express下使用redis管理session
Session实现原理 实现请求身份验证的方式很多,其中一种广泛接受的方式是使用服务器端产生的Session ID结合浏览器的Cookie实现对Session的管理,一般来说包括以下4个步骤: 服务器 ...
- 【转】Session ID/session token 及和cookie区别
Session + Cookie 知识收集! cookie机制采用的是在客户端保持状态的方案.它是在用户端的会话状态的存贮机制,他需要用户打开客户端的cookie支持.cookie的作用就是为了解决 ...
- :Hibernate逍遥游记-第16管理session和实现对话
1. package mypack; public class Monkey{ private Long id; private String name; private int count; pri ...
- 如何管理Session(防止恶意共享账号)——理论篇
目录 知识要求 背景 技术原理 如何管理Session remember me的问题 附录 知识要求 有一定的WEB后端开发基础,熟悉Session的用法,以及与Redis.Database的配合 本 ...
- JSP 状态管理 -- Session 和 Cookie
Http 协议的无状态性 无状态是指,当浏览器发送请求给服务器的时候,服务器响应客户端请求.但是同一个浏览器再次发送请求给服务器的时候,服务器并不知道它就是刚才那个浏览器 session sessio ...
- Unit07: 状态管理-Session
Unit07: 状态管理-Session web package web; import java.io.IOException; import java.io.PrintWriter; import ...
- [原创]java WEB学习笔记31:会话与状态管理 session机制 概述(定义,session机制,session的声明周期,保存session的方式,Session的创建与删除)
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- php中session_id()函数详细介绍,会话id生成过程及session id长度
php中session_id()函数原型及说明session_id()函数说明:stringsession_id([string$id])session_id() 可以用来获取/设置 当前会话 ID. ...
- Infinite loop when using cookieless session ID on Azure
If you use cookieless session ID and deploy them on Azure, you might get infinite loop when you quer ...
随机推荐
- C#中动态读取配置
有些时候,文件修改需要及时的响应,这个时候就需要实时读取文件,预先想的是写一个计时器,每隔多久运行一次,但是不能实时响应,所以采用监听文件的方式实现读取数据 C#监听文件变化 /// <summ ...
- SpringMVC参数绑定(二)
在springMVC中,提交请求的数据是通过方法形参来接收的,从客户端请求的key/value数据,经过参数绑定,将key/value数据绑定到controller形参上,然后再controller就 ...
- AFN上传多张图片
AFN上传多张图片代码: AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager]; sessionManager.r ...
- 【PostgreSQL-9.6.3】如何实现非自动提交
我们在使用psql工具操作数据库时,事务是自动提交的.也就是说,当我们执行完一条insert或者delete语句后,在不输入commit情况下,这条语句也是提交的.如果不想自动提交,可以使用以下两种方 ...
- oracle 命令记录
监听程序启动停止查看名利: 1.切换到oracle用户:su - oracle 2.查看监听状态:lsnrctl status 3.停止监听:lsnrctl stop 4.启动监听:lsnrctl s ...
- 简单的UIButton按钮动画效果iOS源码
这个是简单的UIButton按钮动画效果案例,源码,简单的UIButton按钮动画,可以自定义button属性. 效果图: <ignore_js_op> 使用方法: 使用时把ButtonA ...
- dubbo之本地调用
本地调用 本地调用使用了 injvm 协议,是一个伪协议,它不开启端口,不发起远程调用,只在 JVM 内直接关联,但执行 Dubbo 的 Filter 链. 配置 定义 injvm 协议 <du ...
- PCL:描述三维离散点的ROPS特征(Code)
前言: 三维点云为三维欧式空间点的集合.对点云的形状描述若使用局部特征,则可分为两种:固定世界坐标系的局部描述和寻找局部主方向的局部描述,ROPS特征为寻找局部主方向的特征描述. 1.寻找主方向(对X ...
- ubuntu操作系统的目录结构
/:根目录,是所有目录的绝对路径的起始点.一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区中 /bin (类似的还有/usr/bin) ...
- Swift Pointer 使用指南
Overview C Syntax Swift Syntax Note const Type * UnsafePointer<Type> 指针可变,指针指向的内存值不可变. Type * ...