使用 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];
}

时间: 2024-11-01 19:02:30

使用 AFNetworking的时候,如何管理 session ID的相关文章

使用 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

php中session_id()函数详细介绍,会话id生成过程及session id长度

php中session_id()函数原型及说明session_id()函数说明:stringsession_id([string$id])session_id() 可以用来获取/设置 当前会话 ID.为了能够将会话 ID 很方便的附加到 URL 之后, 你可以使用常量 SID 获取以字符串格... php中session_id()函数原型及说明 session_id()函数说明: ? 1 string session_id ([ string $id ] ) session_id() 可以用来获

nodejs express下使用redis管理session

Session实现原理 实现请求身份验证的方式很多,其中一种广泛接受的方式是使用服务器端产生的Session ID结合浏览器的Cookie实现对Session的管理,一般来说包括以下4个步骤: 服务器端的产生Session ID 服务器端和客户端存储Session ID 从HTTP Header中提取Session ID 根据Session ID从服务器端的Hash中获取请求者身份信息 使用Express和Redis对Session管理的实现 var session = require('exp

Nginx+Tomcat负载平衡,Redis管理session存储

使用Nginx作为Tomcat的负载平衡器,Tomcat的会话Session数据存储在Redis,能够实现0当机的7x24运营效果.因为将会话存储在Redis中,因此Nginx就不必配置成stick粘粘某个Tomcat方式,这样才能真正实现后台多个Tomcat负载平衡,用户请求能够发往任何一个tomcat主机,当我们需要部署新应用代码时,只要停止任何一台tomcat,所有当前在线用户都会导向到运行中的tomcat实例,因为会话数据被序列化到Redis,在线用户不会受到影响,一旦停掉的tomcat

springboot shiro 前后端分离,解决跨域、过虑options请求、shiro管理session问题、模拟跨域请求

一.解决跨域.过虑options请求问题 1.创建过虑类 import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; im

hibernate的OpenSessionInViewFilter用于管理session

OpenSessionInViewFilter.java 用到hibernate框架时可以在每一个项目中都写一个OpenSessionInViewFilter,用于管理session 1 package cn.jbit.auction.web; 2 3 import java.io.IOException; 4 5 import javax.servlet.Filter; 6 import javax.servlet.FilterChain; 7 import javax.servlet.Fil

Hibernate管理Session和批量操作

Hibernate管理Session Hibernate自身提供了三种管理Session对象的方法 Session对象的生命周期与本地线程绑定 Session对象的生命周期与JTA事务绑定 Hibernate委托程序管理Session对象的生命周期 在Hibernate的配置文件中,hibernate.current_session_context_class属性用于指定Session管理方式,可选值包括 thread:Session对象的生命周期与本地线程绑定 jta*:Session对象的生

cookie禁用后session id传值的问题

上一篇说道session和cookie的关系,一般情况下session是借助于cookie传值的,那么cookie被禁用了,session怎么传id的值,下面介绍两种方法 经常被使用的一种技术叫做URL重写,就是把session id直接附加在URL路径的后面. 附加的方式也有两种,一种是作为URL路径的附加信息,另一种是作为查询字符串附加在URL后面.网络在整个交互过程中始终保持状态,就必须在每个客户端可能请求的路径后面都包含这个session id. 当客户端浏览器中禁止 Cookie,Se

【翻译自mos文章】得到正在运行job的 session id

得到正在运行job的 session id 参考原文: How to get the session Id of the Running Job (Doc ID 1604966.1) 适用于: Oracle Database - Enterprise Edition - Version 9.2.0.8 and later Information in this document applies to any platform. 目标: 怎么得到正在运行job的session id --->注意: