nsurlconnection中调用的身份验证挑战



我正在用链接创建nsurlconnection https://www.wella.com,最终传递给 UIWebView

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/professional/countryselector

粘贴扩展链接时, NSURLConnection毫无问题地工作。我该如何摆脱这一挑战,并能以某种方式与该链接自动更改联系在一起?

编辑:我已经解决了它。但是,问题仍然存在:为什么自动链接更改会导致调用身份验证挑战?

谢谢:muralikrishna的答案我通过实现NSURLConnectionDelegate方法并设置信任凭据:

来管理它:
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    SecTrustRef trust = challenge.protectionSpace.serverTrust;
    NSURLCredential *cred;
    cred = [NSURLCredential credentialForTrust:trust];
    [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
}

最新更新