Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet var webView: UIWebView!
- func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool{
- print("canAuthenticateAgainstProtectionSpace method Returning True")
- return true
- }
- func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge){
- print("did autherntcationchallenge = \(challenge.protectionSpace.authenticationMethod)")
- if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
- print("send credential Server Trust")
- let credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)
- challenge.sender!.useCredential(credential, forAuthenticationChallenge: challenge)
- }else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic{
- print("send credential HTTP Basic")
- let defaultCredentials: NSURLCredential = NSURLCredential(user: "username", password: "password", persistence:NSURLCredentialPersistence.ForSession)
- challenge.sender!.useCredential(defaultCredentials, forAuthenticationChallenge: challenge)
- }else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM{
- print("send credential NTLM")
- } else{
- challenge.sender!.performDefaultHandlingForAuthenticationChallenge!(challenge)
- }
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
- let urlHttps = NSURL(string: "https://mysslweb.com");
- let urlHttp = NSURL(string: "http://google.com");
- let urlRequest = NSURLRequest(URL: urlHttps!);
- let urlConnection:NSURLConnection = NSURLConnection(request: urlRequest, delegate: self)!
- webView.loadRequest(urlRequest)
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement