2012-12-26 17 views
1

我有一個要求,我必須處理一個網站的認證並加載它在一個UIWebView。經過搜索網 的同時,我創建了一個新的NSURLConnection的處理和認證挑戰(如鏈接How to display the Authentication Challenge in UIWebView?)使用在UIWebView iOS中處理驗證。這是如何工作的?

一切工作正常,但我不明白下面的一段代碼。

- (void)connection:(NSURLConnection *)connection 
didReceiveResponse:(NSURLResponse *)response 
{ 

     NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 
     NSString *newUrl = [NSString stringWithFormat:@"%@", response.URL]; 

     // cancel the connection. we got what we want from the response, 
     // no need to download the response data. 
     [connection cancel]; 


     //Start loading the new request in webView 
     NSURL *url =[NSURL URLWithString:newUrl]; 
     NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url]; 

     [webView loadRequest:urlRequest]; 

} 

這裏的WebView簡單地再次加載請求,而不重新發送的cookies.Then任何身份驗證信息我瞭解,的iOS 自動處理cookie管理。但是當我試圖訪問餅乾和後打印驗證,它什麼也沒給我。我用下面的代碼 來檢索所有的cookies。

[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] 

這是如何工作的呢?

回答

0

這是模擬器當時的一些問題。我能夠在設備上運行應用程序時打印Cookie。

相關問題