Skip to content

Instantly share code, notes, and snippets.

@gtaban
Created August 30, 2017 16:00
Show Gist options
  • Save gtaban/dc8289e6a8e0959bd1fe3ab7370fc90a to your computer and use it in GitHub Desktop.
Save gtaban/dc8289e6a8e0959bd1fe3ab7370fc90a to your computer and use it in GitHub Desktop.
Handling a self-signed cert
class MyConnection: URLSessionDelegate {
func httpGet(request: URLRequest) {
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration, delegate: self, delegateQueue:OperationQueue.main)
let task = session.dataTask(with: request){
(data, response, error) -> Void in
if error == nil {
let result = NSString(data: data!, encoding:
String.Encoding.ascii.rawValue)!
NSLog("result %@", result)
}
}
task.resume()
}
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!) )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment