使用 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 ...
随机推荐
- 制作一个 JavaScript 小游戏
简评: 作者学习了编程两个月,边学边做了一个 JavaScript 小游戏,在文中总结了自己在这个过程中的一些体会,希望能给其他初学者一些帮助. 对于很多想学编程但一直没下定决心的同学来说,最大的问题 ...
- android view、viewgroup 事件响应拦截处理机制
文章中会用到部分网络资源,首先将原作者的链接附上. 但是还是会附上数量较大的关于此部分内容的自己的思考. ----------------------------------------------- ...
- 运行Django项目指定IP和端口
默认IP和端口 python manage.py runserver 指定端口: python manage.py runserver 192.168.12.12:8080 此时会报错,我们需要修改配 ...
- 题解报告:hdu 4764 Stone(巴什博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 Problem Description Tang and Jiang are good frie ...
- java 实现将java对象转为yaml文件
首先我们建两个类,以下两个类展示的是一个学生拥有多个手机号码联系人. 先是学生类: package com.ming.yaml.beans; import java.util.ArrayList; i ...
- sql 添加列并设置默认值
ALTER TABLE tablsename ADD fieldname BIT NULL DEFAULT
- JavaScript(基于react+dva)
变量声明 const 和 let:分别表示常量和变量 模板字符串 const user = 'world'; console.log(`hello ${user}`); // hello world ...
- Android Studio Library 编译成 jar,aar
1. 导入Library ,打开Library 的build gradle 在最外面添加如下: /** AVLView 自定义的jar 包名 **/ task clearJar(type: Dele ...
- Windows下错误码全解析
windows系统下,调用函数出错时.可以调用GetLastError函数返回错误码.但是GetLastError函数返回值是DWORD类型,是一个整数.如果想要知道函数调用的真正错误原因,就需要对这 ...
- CentOS 7 中配置通过 daemon 模式启动的 Tomcat 8 服务
距离上次折腾已经有很长一段时间了... 不说这个,刚好有空闲,把这两天折腾的 Tomcat 8 的服务配置整理出来收录一下. 1.JDK安装 1)检查服务器是否预装了 openJdk,如果有就删除,在 ...