原貼地址:http://blog.csdn.net/jinglijun/article/details/9048959
清除所有的cookie 方法:
[html] view plain copy NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]; if (url) { NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url]; for (int i = 0; i < [cookies count]; i++) { NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i]; [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; }
清除某一個特定的cookie方法: [html] view plain copy NSArray * cookArray = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:self.loadURL]]; NSString * successCode = @""; for (NSHTTPCookie*cookie in cookArray) { if ([cookie.name isEqualToString:@"cookiename"]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; } }
清除某一個url緩衝的方法:
[html] view plain copy [[NSURLCache sharedURLCache] removeCachedResponseForRequest:[NSURLRequest requestWithURL:url]];
清除所有緩衝方法:
[html] view plain copy [[NSURLCache sharedURLCache] removeAllCachedResponses];