2017-06-29 127 views
0

我創建NSURLConnection的與最終傳遞到UIWebView認證挑戰稱爲NSURLConnection的

NSURL *url = [NSURL URLWithString:[[u stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
self.authRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30]; 
self.authConnection = [NSURLConnection connectionWithRequest:authRequest delegate:self]; 

我意外地收到認證挑戰,當然我目前不處理鏈接https://www.wella.com。 我注意到,使用桌面瀏覽器的時候,當我粘貼上面的鏈接,它的地址被自動更改爲https://www.wella.com/professional/countryselector

當粘貼擴展路段,NSURLConnection作品沒有任何問題。 我怎樣才能擺脫這個挑戰,並可以以某種方式連接到該鏈接自動更改?

編輯:我解決了它。但問題仍然存在:爲什麼自動鏈接更改會導致調用身份驗證質詢?

回答

1

感謝:

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
    SecTrustRef trust = challenge.protectionSpace.serverTrust; 
    NSURLCredential *cred; 
    cred = [NSURLCredential credentialForTrust:trust]; 
    [challenge.sender useCredential:cred forAuthenticationChallenge:challenge]; 
} 
Muralikrishna's answer 我已經通過實現 NSURLConnectionDelegate方法和設置的信任憑證管理它