Post marked as solved
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
contentPostList.repliessolved.tooltip
Replied In
how do i ignore ssl when connecting to url
There's not that many examples out there for this. This is what I had to do to make it work at my end (Swift 5.7+, based on @eskimo 's answer above):
Async
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge) async -> (URLSession.AuthChallengeDisposition, URLCredential?) {
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
guard let serverTrust = challenge.protectionSpace.serverTrust, serverTrust.isSelfSigned ?? false else {
return (.useCredential, nil)
}
return (.useCredential, URLCredential(trust: serverTrust))
}
return (.performDefaultHandling, nil)
}
Sync
func urlSession(_: URLSession, task _: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
guard let serverTrust = challenge.protectionSpace.serverTrust, serverTrust.isSelfSigned ?? false else {
return completionHandler(.useCredential, nil)
}
return completionHandler(.useCredential, URLCredential(trust: serverTrust))
}
return completionHandler(.performDefaultHandling, nil)
}