Swift-SRWebClient icon indicating copy to clipboard operation
Swift-SRWebClient copied to clipboard

Support for self signed certificates

Open ch4vi opened this issue 10 years ago • 1 comments

For test in development, sometimes we have a server without trusted certificates.

ch4vi avatar Feb 10 '15 17:02 ch4vi

You can achieve this by adding delegates.

public func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool { return protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust }

public func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { if challenge.protectionSpace.host == "www.symonty.org" //domain example { let credentials = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!) challenge.sender!.useCredential(credentials, forAuthenticationChallenge: challenge) } } challenge.sender!.continueWithoutCredentialForAuthenticationChallenge(challenge) }

symonty avatar Nov 15 '15 06:11 symonty