iOS 设置UIWebView允许请求https网络请求
2016-09-18 09:25
489 查看
不使用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];
}
- (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];
}
相关文章推荐
- iOS 网络请求设置https连接方式
- iOS 开发 设置网络请求允许使用http
- React-Native 在iOS9之后,网络请求默认为Https请求,如需支持Http,修改info.plist文件添加键值对设置允许http访问。
- iOS 开发 设置网络请求允许使用http
- [IOS]UIWebView 请求网络页面或者加载本地资源页面
- IOS 网络请求中设置cookie
- IOS学习 网络HTTP Get和Post请求与登录界面加密 涉及按钮边框圆角与颜色设置
- iOS - 简述二次封装AFN,设置请求头,https安全策略
- IOS网络请求的一些需要记录的info设置
- ios 简单的设置图片等比例缩放请求的网络图片
- iOS中https的网络请求的配置
- iOS开发 https请求网络web自定义证书不信任解决方案
- iOS客户端校验https网络请求证书
- ios 网络请求总结加强对中文的处理 问题:URL不允许写中文 在GET请求中,相关代码段打断点以验证。
- iOS网络——NSURLCache设置网络请求缓存
- [IOS]UIWebView 请求网络页面或者加载本地资源页面
- 使用burpsuite监控设备(如ios,android)网络http,https请求
- IOS 网络请求中设置cookie
- IOS UIWebView请求https站点及html页面内部ajax请求 对https的支持
- ios开发网络学习六:设置队列请求与RunLoop