title: UIWebView windows authentication in swift programming
body: <p>I have a problem with the UIWebView. I cant open a Website with Windows Authentication... In the Safari Browser a pop-up appears, therefor in the WebView Control happened nothing.</p>
  
  <p>Can someone help me with this problem?</p>
  
  <p>Here my code</p>
  
  <pre><code>class MainViewController: UIViewController, UIWebViewDelegate, MFMailComposeViewControllerDelegate {
  
      @IBOutlet weak var webView: UIWebView!
  
      override func viewDidLoad() {
          super.viewDidLoad();
  
          webView.delegate = self;
  
          let url = NSURL (string: "http://test.raphaels.com/mobile/");
          let requestObj = NSURLRequest(URL: url);
          webView.loadRequest(requestObj);
      }
  }
  </code></pre>
  
  <p>This piece code of works perfectly fine on non-secure server(URL) on iOS simulator, thats iPhone simulator/emulator on Xcode. But when I use the above URL(can only be accessed from intranet). It asks for username/password in browser and stops in iPhone emulator. Please help me, how can i supply username and password. I searched on internet and found many examples, unfortunately none of them was in swift programming.</p>
  
  <p>I tried to write a solution which fails, so below is the failing code</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad();
  
      webView.delegate = self;
  
  
      let username = "username11";
      let password = "password22";
      let loginString = NSString(format: "%@:%@", username, password);
      let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!;
      let base64LoginString = loginData.base64EncodedStringWithOptions(nil);
  
      // create the request
      let url = NSURL (string: "http://test.raphaels.com/mobile/");
      let request = NSMutableURLRequest(URL: url)
      request.HTTPMethod = "POST"
      request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
  
  
  
  
      webView.loadRequest(request);
  }
  </code></pre>