NSURLConnection

时间:2017-06-29 10:07:42

标签: ios uiwebview nsurlconnection

我使用链接https://www.wella.com创建NSURLConnection,最后传递给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可以正常工作。 我怎样才能摆脱这种挑战,并且能够以某种方式与链接自动更改相关联?

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

1 个答案:

答案 0 :(得分:1)

感谢:Muralikrishna's answer 我通过实施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];
}