2012-09-10 43 views
0

我正在研究需要从我们基于iis的网站下载网页的应用程序。如果我在我的iPad上登录到我的无线连接的域名,我所连接的站点似乎使用该登录名作为我的凭据。但是,如果我没有连接到域,或者我作为无权访问该网页的用户进行连接,它会触发didReceiveAuthenticationChallenge,否则它不会。如果我使用Safari连接到相同的页面,它会要求进行认证。我希望每次都能让应用程序进行身份验证。任何帮助,将不胜感激。在ios应用程序中影响didReceiveAuthenticationChallenge的域名登录

代码请求页面:

NSError *error = nil; 
// assign the cmh url from user prefs 
NSURL *url = [NSURL URLWithString:cmhUrl]; 

// Put that URL into an NSURLRequest 
NSURLRequest *req = [NSURLRequest requestWithURL:url]; 

[req setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; 

// Create a connection that will exchange this request for data from the URL 
connection = [[NSURLConnection alloc] initWithRequest:req 
              delegate:self 
            startImmediately:YES]; 

回答

0

看起来,当你在Safari中验证身份验证令牌保存在NSHTTPCookieStorage等。而当您从代码发出请求时,存储中的所有Cookie都会添加到标题中,因此无需再次请求令牌。
尝试你发出请求之前清除存储:

NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
for (NSHTTPCookie *cookie in cookieStorage.cookies) { 
    [cookieStorage deleteCookie:cookie]; 
} 

希望这有助于。

相关问题