【问题标题】:Authentication challenge called in NSURLConnectionNSURLConnection 中调用的身份验证质询
【发布时间】:2017-06-29 19:05:28
【问题描述】:

我正在创建带有链接 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 可以正常工作。 我怎样才能摆脱这个挑战,它是否与链接自动更改有某种联系?

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

【问题讨论】:

    标签: ios uiwebview nsurlconnection


    【解决方案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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多