使用 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 ...
随机推荐
- 函数中的this的四种绑定形式
目录 this的默认绑定 this的隐式绑定 隐式绑定下,作为对象属性的函数,对于对象来说是独立的 在一串对象属性链中,this绑定的是最内层的对象 this的显式绑定:(call和bind方法) n ...
- 认识JS的基础对象,定义对象的方法
JS的基础对象: 1.window //窗口对象 2.document //文档对象 3.document.documentElement //html对象 4.docume ...
- Java多线程技术-Volatile关键字解析
分析volatile关键字可以从这三个方面分析,什么是程序的原子性,什么是程序的可见性,什么是程序的有序性 什么是程序的原子性 以下语句那些是原子操作? public class ThreadCoun ...
- JQuery 数据加载中禁止操作页面
比较常见的做法,但对我而言是第一次做,记录一下. 为了把找来的loading.gif 的背景色设置为透明,还特意装了quicktime. 有学到一些额外的东西. 先将div及img定义好 <bo ...
- 关于SSL证书配置、升级的一些问题总结
SSL会成为网站.APP.小程序(小程序已经强制使用https)等项目的标配.关于SSL证书安装使用的问题今天总结下,以备用. 环境配置:windows server 2008 R2和IIS7.0 1 ...
- 联想笋尖S90(S90-t 、S90-u)解锁BootLoader
工具下载链接: http://pan.baidu.com/s/1eSgZuka 备用下载链接: http://pan.baidu.com/s/1dFKqSId 本篇教程,仅限于联想笋尖S90(S90- ...
- WM消息大全
消息名 消息值 说明 WM_CREATE 0x0001 应用程序创建一个窗口 WM_DESTROY 0x0002 一个窗口被销毁 WM_MOVE 0x0003 移动一个窗口 WM_SIZE 0x000 ...
- <转>python 发送邮件实例
文件形式的邮件 #!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.text import MIMEText fr ...
- C 预处理程序指令(CPP)
#include 文件 提供的东西 stdio 提供 FILE.stdin.stdout.stderr 和 fprintf() 函数系列 stdlib 提供 malloc().calloc()和 re ...
- DD打卡
一.安装逍遥安卓模拟器 二.安装钉钉 三.设置当前GPS座标 位置模拟器: 链接: https://pan.baidu.com/s/1TC5QkrGAgHOJWtzJnX6vhA 提取码: bpu8 ...