开发者

How to Destroy NSHTTPCookies?

开发者 https://www.devze.com 2022-12-22 01:04 出处:网络
I am running a Post call to a URL and logging into a system. This is working, but after the login, I am attempting to retrieve the cookies – but when I do this:

I am running a Post call to a URL and logging into a system. This is working, but after the login, I am attempting to retrieve the cookies – but when I do this:

NSArray *allCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:mywebsite"]]; 
NSLog(@"How many Cook开发者_JAVA百科ies: %d", allCookies.count);

I am getting a response of “How many Cookies: 0”

The problem is that when I close the App and then reopen, it is connecting using the info from my previous login.

What is going on here? Why is it telling me there are zero cookies? How can I get rid of these cookies?


See if you can find and delete them this way:

NSHTTPCookieStorage * sharedCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray * cookies = [sharedCookieStorage cookies];
for (NSHTTPCookie * cookie in cookies){
    NSLog(@"%@",cookie.domain);
    if ([cookie.domain rangeOfString:@"yourdomain"].location != NSNotFound){
            NSLog(@"deleting");
            [sharedCookieStorage deleteCookie:cookie];
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号