不使用AFNetworking的前提下, UIWebView默认不加载https协议的请求
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES animated:YES];
self.webView= [[UIWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.webView];
_request = [NSMutableURLRequest requestWithURL:self.webUrl];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:_request delegate:self];
}
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
if ([challenge previousFailureCount]== 0) {
//NSURLCredential 这个类是表示身份验证凭据不可变对象。凭证的实际类型声明的类的构造函数来确定。
NSURLCredential* cre = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:cre forAuthenticationChallenge:challenge];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[self.webView loadRequest:_request];
[connection cancel];
}