Created
August 30, 2017 16:00
-
-
Save gtaban/dc8289e6a8e0959bd1fe3ab7370fc90a to your computer and use it in GitHub Desktop.
Handling a self-signed cert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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