swift – Alamofire不处理身份验证挑战

swift – Alamofire不处理身份验证挑战,第1张

概述利用Alamofire,我注意到下面的代码没有被断点击中.我建立连接,并收到以下错误:(错误域= NSURLErrorDomain代码= -1200“发生SSL错误,无法建立与服务器的安全连接.”UserInfo = 0x1741b3f60 {_kCFStreamErrorCodeKey = -9806,NSLocalizedRecoverySuggestion =是否要连接到服务器?,NSUnd 利用Alamofire,我注意到下面的代码没有被断点击中.我建立连接,并收到以下错误:(错误域= NSURLErrorDomain代码= -1200“发生SSL错误,无法建立与服务器的安全连接.”UserInfo = 0x1741b3f60 {_kcfStreamErrorCodeKey = -9806,NSLocalizedRecoverySuggestion =是否要连接到服务器?,NSUnderlyingError = 0x17484b8e0“ *** 作无法完成.(kcfErrorDomainCFNetwork error -1200.)”,NSLocalizedDescription =发生SSL错误,无法建立与服务器的安全连接.,

func connection(urlRequest:NSURLRequest,rest:RESTFull?,completion: (AnyObject?,NSError?)->VoID){    let req = request(urlRequest).responseJsON(options: .AllowFragments) { (_,response,data,error) -> VoID in        if let actualData: AnyObject = data {            completion(actualData,nil)        }else {            completion(nil,error)        }    }    req.delegate.taskDIDReceiveChallenge = { session,_,challenge in        println("Got challenge: \(challenge),in session \(session)")        var disposition: NSURLSessionAuthChallengedisposition = .UseCredential        var credential: NSURLCredential = NSURLCredential()        if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust){            disposition = NSURLSessionAuthChallengedisposition.UseCredential            credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)        }        return(disposition,credential)    }}
解决方法 您无法将值设置为Request Class的taskDIDReceiveChallenge.您可以改用Manager类的委托.

Manager.sharedInstance.delegate.taskDIDReceiveChallenge = { session,challenge in    print("Got challenge: \(challenge),in session \(session)")    var disposition: NSURLSessionAuthChallengedisposition = .UseCredential    var credential: NSURLCredential = NSURLCredential()    if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust){        disposition = NSURLSessionAuthChallengedisposition.UseCredential        credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)    }    return(disposition,credential)}
总结

以上是内存溢出为你收集整理的swift – Alamofire不处理身份验证挑战全部内容,希望文章能够帮你解决swift – Alamofire不处理身份验证挑战所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/999842.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存