如何从NSHTTPCookieStorage更多的一次清除cookie? [英] How to clear cookies from NSHTTPCookieStorage more then once?

查看:413
本文介绍了如何从NSHTTPCookieStorage更多的一次清除cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌面应用程式连结到在Google App Engine上代管的网页应用程式。一旦它认证它获得一个authtoken cookie,它传递所有未来的请求。一切正常。



但现在我想添加退出。我试图这样实现注销:

   - (void)signOut {
NSHTTPCookieStorage * cookieStorage = [ NSHTTPCookieStorage sharedHTTPCookieStorage];
for(NSHTTPCookie * each in [[[cookieStorage cookiesForURL:[NSURL URLWithString:self.serviceRootURLString]] copy] autorelease]){
[cookieStorage deleteCookie:each];
}
[self clearCredentialStorage];
}

问题是,它似乎只是第一次工作。例如我可以打开我的应用程序。登录。提出一些请求。退出。然后下次我提出请求时,我被要求再次验证。好!



但是在我第二次验证后,问题发生了。认证工作。我得到authtoken cookie。我可以请求。但是,当我尝试第二次注销(没有重新启动我的应用程序)authtoken cookie似乎没有被删除。它似乎从我的应用程序的角度删除...我问NSHTTPCookieStorage的Cookie,它有我的URL,它不返回。但如果我尝试另一个请求(应该需要authtoken cookie)的请求只是工作,我没有得到401的答复,我从来没有要求再次认证。



因此,如果我理解正确的东西,似乎cookies从我的角度删除,但它们不会从底层的URL加载框架的角度删除。



可能感兴趣的是,问题与以下相关: http:// www.macworld.com/article/143343/2009/10/safaricookieproblems.html



有没有人知道如何一致地实现注销功能

解决方案


$ b div>

Theory:还有其他相关的Cookie不在您服务的网址下,因为某些请求导致重定向,可能会在您的系统上获取或设置Cookie。



另外:我建议使用tcpdump进行调试。您将能够准确了解网络上发生的情况,以及确切了解发送或接收的Cookie。


My desktop app connects to a web application that's hosted on Google App engine. Once it authenticates it gets an authtoken cookie that it passes along for all future requests. That all works.

But now I want to add "Sign out". I’ve tried to implement Sign Out like this:

- (void)signOut {
    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (NSHTTPCookie *each in [[[cookieStorage cookiesForURL:[NSURL URLWithString:self.serviceRootURLString]] copy] autorelease]) {
        [cookieStorage deleteCookie:each];
    }
    [self clearCredentialStorage];
}

The problem is that it only seems to work the first time. For instance I can open my app. Sign in. Make some requests. Sign out. Then next time I make a request I'm asked to authenticate again. Good!

But after I authenticate the second time the problem happens. The authentication works. I get the authtoken cookie. I can make requests. But then when I try to log out for the second time (without restarting my app) the authtoken cookie doesn’t seem to get deleted. It does seem deleted from my apps perspective... I ask NSHTTPCookieStorage for the cookies that it has my URL and it returns none. But if I try to make another request (that should require the authtoken cookie) the request just works, I don’t get a 401 response and I'm never asked to authenticate again.

So if I'm understanding things correctly it seems that the cookies are deleted from my perspective, but they are not deleted from the underlying URL loading frameworks perspective.

Of possible interest, maybe the problem is related to: http://www.macworld.com/article/143343/2009/10/safaricookieproblems.html

Does anyone know how to consistently implement "log out" functionality in an app that interacts with a web service?

Thanks, Jesse

解决方案

Theory: there are other relevant cookies that are not under your service's URL, because some requests result in a redirect which may get or set cookies on your system.

Also: I recommend using tcpdump for debugging. You'll be able to see exactly what is going over the network, and know exactly what cookies are being sent or received.

这篇关于如何从NSHTTPCookieStorage更多的一次清除cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆