2012-09-10 45 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]; 
} 

希望這有助於。

相關問題