?NSHTTPCookie
在iOS中使用NSHTTPCookie类封装一条cookie,通过NSHTTPCookie的方法读取到cookie的通用属性。
- (NSUInteger)version;
- (NSString *)name;
- (NSString *)value;
- (NSString *)domain;
- (NSString *)path;
- (BOOL)isSessionOnly;
现在,我们需要读取cookie字段中的CRFS-TOKEN字段,
NSHTTPCookieStorage *cookie=[NSHTTPCookieStoragesharedHTTPCookieStorage];
for (NSHTTPCookie *cookieitem in? [cookie cookies]) {
? ? ? NSLog(@"COOKIE PATH :: %@",cookieitem.path);
? ? ? NSLog(@"COOKIE VERSION :: %d",cookieitem.version);
? ? ? NSLog(@"COOKIE DOMAIN :: %@",cookieitem.domain);
? ? ? NSLog(@"COOKIE NAME :: %@",cookieitem.name);
? ? ? NSLog(@"COOKIE VALUE :: %@",cookieitem.value);
? ? ? NSLog(@"COOKIE ISSESSIONONLY ::%d",cookieitem.isSessionOnly);
}
查看运行结果:
这样我们就可以读取cookie中的字段值。