1

What is the best way to load a website into a webview by using https? Is there a easy way to do so?

Thanks

Philip

Philip
  • 39
  • 1
  • 4
  • Personally, because of security problem, people usually avoid to load login page using UIWebView (which can be fake quite easily), so I think you may need to go for some oauth or openID – vodkhang May 25 '10 at 16:07
  • Yes but in this case its a website thats requires https communication but when I do this like I do it with a standard web page it won't work – Philip Jun 03 '10 at 22:43
  • Chris gave you the answer below for the short answer of "Loading HTTPS:// into UIWebView." There are problems with naive loading (for example mixing HTTP/HTTPS and SSL/TLS stripping; and HTTP -> HTTPS redirects). I'm trying to figure out how to use UIWebView securely at [iPhone and UIWebView: Force HTTPS (rewrite URLs on the fly)](http://stackoverflow.com/questions/12994602/iphone-and-uiwebview-force-https-rewrite-urls-on-the-fly). I'm beginning to think a UIWebView cannot be used securely. – jww Oct 21 '12 at 20:38

1 Answers1

1

The easiest way I know of is...

NSString *urlAddress = @"https://www.google.com";

//Create a URL object from the string 'urlAddress'
NSURL *url = [NSURL URLWithString:urlAddress];

//Create a URL Request Object from NSURL object 'url'
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the NSURLRequest object 'requestObj' in the UIWebView.
[webView loadRequest:requestObj];

And of course you can condense this into a one-liner...

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.google.com"]]];
Chris Cashwell
  • 22,308
  • 13
  • 63
  • 94