didReceiveAuthenticationChallenge只调用一次iPhone [英] didReceiveAuthenticationChallenge getting called only once iPhone

查看:225
本文介绍了didReceiveAuthenticationChallenge只调用一次iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NSURLConnection 连接到服务器。服务器要求我使用委托方法的基本身份验证: - didReceiveAuthenticationChallenge 。但这只被召唤一次。如果我将密码更改为某个不同的值,那么这个委托方法不会被调用,并且我的登录成功了吗?

I am connecting to server using NSURLConnection. The server asks for basic authentication for which I am using the delegate methods :-didReceiveAuthenticationChallenge. But this gets called only once. If I change password to some different value, then this delegate methods does not get called and it takes my login as successful?

任何形式的帮助都将受到赞赏。

Any kind of help will be appreciated.

谢谢。

推荐答案

解决了!

事实证明 NSURLConnection 实际上表现正常 - 也就是说,每次验证质询都会调用 didReceiveAuthenticationChallenge:

It turns out that NSURLConnection was actually behaving correctly - that is, didReceiveAuthenticationChallenge: was being called for every authentication challenge.

问题在于服务器在第一个之后没有发送挑战。结果是因为服务器正在设置cookie。

The problem was that the server was not sending challenges after the first one. This turned out to be because the server was setting a cookie.

您可以通过简单地删除cookie来强制执行新的挑战。因为此服务器没有其他有用的cookie,我只删除它们全部:

You can force a new challenge by simply deleting the cookie. Because there are no other useful cookies for this server, I just delete all of them:

- (void)clearCookiesForURL {
    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookies = [cookieStorage cookiesForURL:_URL];
    for (NSHTTPCookie *cookie in cookies) {
        NSLog(@"Deleting cookie for domain: %@", [cookie domain]);
        [cookieStorage deleteCookie:cookie];
    }
}

这篇关于didReceiveAuthenticationChallenge只调用一次iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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