Cookies and Custom Protocols
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/CookiesandCustomProtocols/CookiesandCustomProtocols.html#//apple_ref/doc/uid/10000165i-CH10-SW3
If your app needs to manage cookies programmatically, such as adding and deleting cookies or determining which cookies should be accepted, read Cookie Storage.
If your app needs to support a URL-based protocol that NSURL does not support natively, you can register your own custom protocol class that provides the needed support. To learn more, read Protocol Support.
Cookie Storage
Due to the stateless nature of the HTTP protocol, clients often use cookies to provide persistent storage of data across URL requests. The URL loading system provides interfaces to create and manage cookies, to send cookies as part of an HTTP request, and to receive cookies when interpreting a web server’s response.
The NSHTTPCookie class encapsulates a cookie, providing accessors for many of the common cookie attributes. This class also provides methods to convert HTTP cookie headers to NSHTTPCookie instances and convert an NSHTTPCookie instance to headers suitable for use with an NSURLRequest object. The URL loading system automatically sends any stored cookies appropriate for an NSURLRequest object unless the request specifies not to send cookies. Likewise, cookies returned in an NSURLResponse object are accepted in accordance with the current cookie acceptance policy.
The NSHTTPCookieStorage class provides the interface for managing the collection of NSHTTPCookie objects shared by all apps.
iOS Note: Cookies are not shared between apps in iOS.
NSHTTPCookieStorage allows an app to specify a cookie acceptance policy. The cookie acceptance policy controls whether cookies should always be accepted, never be accepted, or be accepted only from the same domain as the main document URL.
Note: Changing the cookie acceptance policy in an app affects the cookie acceptance policy for all other running apps.
When another app changes the cookie storage or the cookie acceptance policy, NSHTTPCookieStorage notifies an app by posting the NSHTTPCookieManagerCookiesChangedNotification and NSHTTPCookieStorageAcceptPolicyChangedNotification notifications.
For more information, see NSHTTPCookieStorage Class Reference and NSHTTPCookie Class Reference.
Protocol Support
The URL loading system design allows a client app to extend the protocols that are supported for transferring data. The URL loading system natively supports the http, https, file, ftp, and data protocols.
You can implement a custom protocol by subclassing NSURLProtocol and then registering the new class with the URL loading system using the NSURLProtocol class method registerClass:. When an NSURLSession object initiates a connection for an NSURLRequest object, the URL loading system consults each of the registered classes in the reverse order of their registration. The first class that returns YES for a canInitWithRequest: message is used to handle the request.
If your custom protocol requires additional properties for its requests or responses, you support them by creating categories on the NSURLRequest, NSMutableURLRequest, and NSURLResponse classes that provide accessors for those properties. The NSURLProtocol class provides methods for setting and getting property values in those accessors.
The URL loading system is responsible for creating and releasing NSURLProtocol instances when connections start and complete. Your app should never create an instance of NSURLProtocol directly.
When an NSURLProtocol subclass is initialized by the URL loading system, it is provided a client object that conforms to the NSURLProtocolClientprotocol. The NSURLProtocol subclass sends messages from the NSURLProtocolClient protocol to the client object to inform the URL loading system of its actions as it creates a response, receives data, redirects to a new URL, requires authentication, and completes the load. If the custom protocol supports authentication, then it must conform to the NSURLAuthenticationChallengeSender protocol.
For more information, see NSURLProtocol Class Reference.
Cookies and Custom Protocols的更多相关文章
- sanic官方文档解析之Custom Protocols(自定义协议)和Socket(网络套接字)
1,Custom Protocol:自定义协议 温馨提示:自定义协议是一个高级用法,大多数的读者不需要用到此功能 通过特殊的自定义协议,你可以改变sanic的协议,自定义协议需要继承子类asyncio ...
- iOS - NSURLSession 网络请求
前言 NS_CLASS_AVAILABLE(NSURLSESSION_AVAILABLE, 7_0) @interface NSURLSession : NSObject @available(iOS ...
- NSURLSession 网络请求
1.NSURLSession 在 iOS9.0 之后,以前使用的 NSURLConnection 过期,苹果推荐使用 NSURLSession 来替换 NSURLConnection 完成网路请求相关 ...
- Android Weekly Notes Issue #235
Android Weekly Issue #235 December 11th, 2016 Android Weekly Issue #235 本期内容包括: 开发一个自定义View并发布为开源库的完 ...
- 实现SQL Server 2008 Reporting Services匿名访问报表有两种方法
一.通过修改SQL Server 2008的配置文件,去掉Windows的验证. 1.首先我们找到SQL安装目录下的两个Web.config配置文件,默认安装目录分别是(C:\Program File ...
- iOS开发之网络编程--6、NSURLSessionConfiguration笔记
NSURLSessionConfiguration对象用于初始化NSURLSession对象. 展开请求级别中与NSMutableURLRequest相关的可供选择的方案,我们可以看到NSURLSes ...
- SQOOP Load Data from Oracle to Hive Table
sqoop import -D oraoop.disabled=true \ --connect "jdbc:oracle:thin:@(description=(address=(prot ...
- iPad accessory communication through UART
We manufacture a new accessory for iPad/iPhone which should transfer commands to the iPad. We like t ...
- iOS 开发中使用 NSURLProtocol 拦截 HTTP 请求
这篇文章会提供一种在 Cocoa 层拦截所有 HTTP 请求的方法,其实标题已经说明了拦截 HTTP 请求需要的了解的就是 NSURLProtocol. 由于文章的内容较长,会分成两部分,这篇文章介绍 ...
随机推荐
- Linux内核klist链表分析
1.前言 在Linux内核的源码中,除了简洁的list链表外,内核还有klist链表,它是list链表的线程安全版本,在结构体中提供了整个链表的自旋锁,对链表节点查找.插入和删除等操作,都需要先获得这 ...
- 【转帖】威盛x86 AI处理器架构、性能公布:媲美Intel 32核心
威盛x86 AI处理器架构.性能公布:媲美Intel 32核心 https://www.cnbeta.com/articles/tech/920559.htm 除了Intel.AMD,宝岛台湾的威盛也 ...
- 命令(Command)模式
命令模式又称为行动(Action)模式或者交易(Transaction)模式. 命令模式把一个请求或者操作封装到一个对象中.命令模式允许系统使用不同的请求把客户端参数化,对请求排队或者记录请求日志,可 ...
- 如何申请腾讯地图用户Key
打开网页https://lbs.qq.com/,进入腾讯位置服务. 单击[登录],登录腾讯账号(本文以QQ登录为例),如果首次登陆腾讯位置服务,则提示注册开发者账号. 选择箭头处[注册新账号].填写手 ...
- Lodash之throttle(节流)与debounce(防抖)总结
全手打原创,转载请标明出处:https://www.cnblogs.com/dreamsqin/p/11305028.html 先重点说一下可能遇到的坑:主要在原本默认参数的设置以及两个方法的选择上, ...
- MySQL一主二从复制环境切换主从库
假设有一个一主二从的环境,当主库M出现故障时,需要将其中一个从库S1切换为主库,同时将S2指向新的主库S1,如果可能,需要将故障的主库M修复并重置为新的从库. 搭建一主二从复制环境可参考:mysql5 ...
- spring cloud应用
1.什么是注册中心 (1)就是首先有一个eureka server,服务的注册与发现的中心(2)你如果写好了一个服务,就可以将其注册到eureka server上去(3)然后别人的服务如果要调用你的服 ...
- SQL server中常用sql语句
--循环执行插入10000条数据 declare @ID intbeginset @ID=1 while @ID<=10000begininsert into table_name values ...
- APS.NET MVC + EF (05)---控制器
Controller(控制器)在ASP.NET MVC中负责控制所有客户端与服务端的交互,并且负责协调Model与View之间数据传递,是ASP.NET MVC框架核心.Controller为ASP. ...
- 这两个小技巧,让我的SQL语句不仅躲了坑,还提升了1000 倍
原文: https://cloud.tencent.com/developer/article/1465618 本次来讲解与 SQL 查询有关的两个小知识点,掌握这些知识点,能够让你避免踩坑以及提高查 ...