Answers:
您的应用程序在[NSHTTPCookieStorage sharedHTTPCookieStorage]
容器中有其自己的“ cookie jar” 。
您可以通过以下方法快速查看应用程序的Cookie罐中的Cookie:
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
NSLog(@"%@", cookie);
}
有几种方法可用于过滤和操作。看看在NSHTTPCookieStorage文档访问饼干和NSHTTPCookie访问各个Cookie属性的文件。
cookiesForURL
方法代替cookies
感谢指针Alex!为此,我将放入我使用Alex的示例创建的“ cookie dumper”。也许这会帮助别人。
- (void) dumpCookies:(NSString *)msgOrNil {
NSMutableString *cookieDescs = [[[NSMutableString alloc] init] autorelease];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
[cookieDescs appendString:[self cookieDescription:cookie]];
}
NSLog(@"------ [Cookie Dump: %@] ---------\n%@", msgOrNil, cookieDescs);
NSLog(@"----------------------------------");
}
- (NSString *) cookieDescription:(NSHTTPCookie *)cookie {
NSMutableString *cDesc = [[[NSMutableString alloc] init] autorelease];
[cDesc appendString:@"[NSHTTPCookie]\n"];
[cDesc appendFormat:@" name = %@\n", [[cookie name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[cDesc appendFormat:@" value = %@\n", [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[cDesc appendFormat:@" domain = %@\n", [cookie domain]];
[cDesc appendFormat:@" path = %@\n", [cookie path]];
[cDesc appendFormat:@" expiresDate = %@\n", [cookie expiresDate]];
[cDesc appendFormat:@" sessionOnly = %d\n", [cookie isSessionOnly]];
[cDesc appendFormat:@" secure = %d\n", [cookie isSecure]];
[cDesc appendFormat:@" comment = %@\n", [cookie comment]];
[cDesc appendFormat:@" commentURL = %@\n", [cookie commentURL]];
[cDesc appendFormat:@" version = %d\n", [cookie version]];
// [cDesc appendFormat:@" portList = %@\n", [cookie portList]];
// [cDesc appendFormat:@" properties = %@\n", [cookie properties]];
return cDesc;
}
NSHTTPCookieStorage
:macdevelopertips.com/objective-c/objective-c-categories.html
亚历克斯有一个很好的想法,将其归为一类。这是我最终使用的内容:
NSHTTPCookieStorage + Info.h
#import <Foundation/Foundation.h>
@interface NSHTTPCookieStorage (Info)
+ (NSDictionary*) describeCookies;
+ (NSDictionary *) describeCookie:(NSHTTPCookie *)cookie;
@end
NSHTTPCookieStorage.m
@implementation NSHTTPCookieStorage (Info)
+ (NSDictionary*) describeCookies {
NSMutableDictionary *descriptions = [NSMutableDictionary new];
[[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] enumerateObjectsUsingBlock:^(NSHTTPCookie* obj, NSUInteger idx, BOOL *stop) {
[descriptions setObject:[[self class] describeCookie:obj] forKey:[[obj name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}];
NSLog(@"Cookies:\n\n%@", descriptions);
return descriptions;
}
+ (NSDictionary *) describeCookie:(NSHTTPCookie *)cookie {
return @{@"value" : [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
@"domain" : [cookie domain] ? [cookie domain] : @"n/a",
@"path" : [cookie path] ? [cookie path] : @"n/a",
@"expiresDate" : [cookie expiresDate] ? [cookie expiresDate] : @"n/a",
@"sessionOnly" : [cookie isSessionOnly] ? @1 : @0,
@"secure" : [cookie isSecure] ? @1 : @0,
@"comment" : [cookie comment] ? [cookie comment] : @"n/a",
@"commentURL" : [cookie commentURL] ? [cookie commentURL] : @"n/a",
@"version" : @([cookie version]) };
}
@end
使输出更加“ JSON-y” ...
在sandbox:Library->Cookies->Cookies.binarycookies
但不能.binarycookie
直接打开s的情况下,可以运行脚本:
下载并安装Python
在终端上运行“ Python BinaryCookieReader.py”
如您所见,输出日志包含详细的Cookie描述