问:

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

最新文章

  1. 如何捕获access violation异常
  2. bk.
  3. 修改Broforce无限人数,死亡不减反加
  4. 提示29. 怎样避免延迟加载或Load()阅读器问题
  5. 【工具篇】xshell
  6. wiki oi 3115高精度练习之减法
  7. 解决IE下Ajax请求无效
  8. AS-->如何更高效的使用 Gradle, 快速build apk
  9. CodeForces 626D Jerry's Protest
  10. 【转】python time模块详解
  11. java并发包——阻塞队列BlockingQueue及源码分析
  12. C++ Primer 有感(复制控制)
  13. Spring boot 发送邮件示例
  14. 从.Net到Java学习第八篇——SpringBoot实现session共享和国际化
  15. Vue开发与调试工具
  16. 硬件篇之MMU
  17. BZOJ1011:[HNOI2008]遥远的行星(乱搞)
  18. 第十九章,指针小练习(C++)
  19. LINUX的文件按时间排序
  20. I.MX6 U-boot lvds display hacking

热门文章

  1. javascript之模块加载方案
  2. rancher导入k8s集群后添加监控无数据
  3. 工作2-5年,身为iOS开发的我应该怎么选择进修方向?
  4. 【DP】编辑距离
  5. Spring的AOP机制---- 切入点表达式---- 切入点表达式
  6. Spring Cloud (2) 服务消费者-基础
  7. 前端编码规范(2)HTML 规范
  8. Android点击跳转到淘宝的某一商品详情页或者某一店铺页面
  9. 【Oracle】DBMS_STATS.GATHER_TABLE_STATS
  10. C# 获取正在使用的Mac地址