在UIWebView中加载HTTPS URL [英] Load HTTPS url in a UIWebView

查看:131
本文介绍了在UIWebView中加载HTTPS URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始进行iPhone编程,我遇到了很大的问题,我无法解决。



所以,我有一个 UIWebview ,我可以毫无问题地加载 HTTP 网址:

  NSString urlAdress; 
urlAdress = @http:// servername;
NSURL * url = [NSURL URLWithString:urlAdress];
NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

它的工作,我的页面加载到我的UIwebView中,但当我替换:

  urlAdress = @http:// servername; 

by

  urlAdress = @https:// servername; 

我有空白屏幕。



I阅读它的正常,但有没有简单的方法来加载我的webview中的https网址?

我读到了 ASIHTTPRequest 但我没有到达实现它。 / p>

我只想加载 HTTPS网址

解决方案

试试这个:

   - (BOOL)连接:(NSURLConnection *)连接canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { 
返回YES;
}


- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[challenge.sender useCredential:[NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}


I begin iPhone programming and I have big problem I cant resolve.

So, I have a UIWebview, I can load HTTP url without problems :

NSString urlAdress;
urlAdress = @"http://servername";
NSURL *url = [NSURL URLWithString:urlAdress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

Its work, my page is load in my UIwebView, but when I replace :

urlAdress = @"http://servername";

by

urlAdress = @"https://servername";

I have blank screen.

I read its normal, but is there easy method to load https url in my webview ?
I read about ASIHTTPRequest but I didnt arrive to implement it.

I just want to load HTTPS URL.

解决方案

Try this :

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    return YES;
}


- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}

这篇关于在UIWebView中加载HTTPS URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆