Alamofire不处理身份验证挑战

编程入门 行业动态 更新时间:2024-10-11 03:24:46
本文介绍了Alamofire不处理身份验证挑战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

利用Alamofire,我注意到下面的代码没有被断点击中。我建立了连接,并收到以下错误:(错误域= NSURLErrorDomain代码= -1200发生SSL错误,无法建立与服务器的安全连接。 UserInfo = 0x1741b3f60 {_kCFStreamErrorCodeKey = -9806,NSLocalizedRecoverySuggestion =是否仍要连接到服务器?,NSUnderlyingError = 0x17484b8e0操作无法完成。(kCFErrorDomainCFNetwork错误-1200。),NSLocalizedDescription =已发生SSL错误,并且已安全连接无法建立服务器。

Utilizing Alamofire, Im noticing that the code below isn't being hit with a breakpoint. I make a connection, and I get the following error: (Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo=0x1741b3f60 {_kCFStreamErrorCodeKey=-9806, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x17484b8e0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1200.)", NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made.,

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) } }

推荐答案

您不能为请求类的taskDidReceiveChallenge设置值。您可以改用Manager类的委托。

You can't set value to the Request Class's taskDidReceiveChallenge. You can use Manager class's delegate instead.

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) }

更多推荐

Alamofire不处理身份验证挑战

本文发布于:2023-11-26 02:14:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   Alamofire

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!