ios uiwebview访问https需不需要使用https

按照惯例写一个UIWebView,用来加载网页:
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_webView.delegate = self;
[self.view addSubview:_webView];
NSURL *url = [NSURL URLWithString:@&/&];
_request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:_request];
run一下看看加载出来了吗?如果发现屏幕一片白并没有出现网页内容,不要惊讶,看看你的控制台是不是报出以下错误:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
这个怎么解决呢?没错ATS设置:去plist文件里添加一项App Transport Security Settings,它是个字典类型,给它增加一对键值,键:Allow Arbitrary Loads ,值设为YES。
以上,搞定ATS设置,网页成功加载了:
Simulator Screen Shot.png
如果你的网页是self signed website,那么你的屏幕应该还是一片白,并且控制台又报错:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
注意:这两次错误并不是一样的,后面数字代码不同
(并不太清楚这个码代表的意思,有知道的朋友请留言告知,感谢。)
NSURLConnection
使用webview加载自签名https站点的时候,必须在请求的时候将该站点设置为安全的,才能继续访问。所以我们需要在webview开始加载网页的时候首先判断判断该站点是不是https站点,如果是的话,先让他暂停加载,用NSURLConnection 来访问改站点,然后再身份验证的时候,将该站点置为可信任站点。然后在用webview重新加载请求。
直接上代码:
#pragma mark - UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationT
NSLog(@&Did start loading: %@ auth:%d&, [[request URL] absoluteString], _authenticated);
if (!_authenticated) {
_authenticated = NO;
_urlConnection = [[NSURLConnection alloc] initWithRequest:_request delegate:self];
[_urlConnection start];
return NO;
return YES;
#pragma mark - NURLConnection delegate
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)
NSLog(@&WebController Got auth challange via NSURLConnection&);
if ([challenge previousFailureCount] == 0)
_authenticated = YES;
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
[[challenge sender] cancelAuthenticationChallenge:challenge];
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
#pragma mark - NSURLConnectionDataDelegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)
NSLog(@&WebController received response via NSURLConnection&);
_authenticated = YES;
[_web loadRequest:_request];
[_urlConnection cancel];
以上设置,可成功加载自签名网页。
但是,虽然加载成功,但是控制台还是报了以下错误:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9843)
文/Goyakod(简书作者)
原文链接:/p/91eb1d8817f2
参考链接:http://blog.csdn.net/yi_zz32/article/details/
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:25451次
排名:千里之外
原创:32篇
转载:22篇
(5)(5)(5)(7)(17)(15)(1)UIWebView 連Https SSL網站 需要Client Certificate- 藍色小舖 BlueShop
台灣最大程式設計社群網站
會員總數:239279
討論主題:185647
歡迎您免費加入會員
討論區選單
行動裝置開發
多媒體 / 網管
&& UIWebView 連Https SSL網站 需要Client Certificate
UIWebView 連Https SSL網站 需要Client Certificate
價值 : 50 QP&&點閱數:2072 回應數:0
130){this.width=130;};if(this.height>130){this.height=130;}' onerror="this.src='/images/nophoto.gif'" onmousewheel="return ChgImgSize(this)" />
最近開發一個項目需要使用UIWebView 連到我們 Https開頭的SSL網站, 並且使用自己發佈的證書, 要用在Client端。 在網路上Search很多, 但是不知道為何都沒辦法正常連到網站, 總是會顯示 SSL Server requires client certificate我的程式碼也提供一下:-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (!_authenticated) {
_authenticated = NO;
_FailedRequest =
_urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[_urlConnection start];
return NO;
return YES;}-(void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
NSURL* baseURL = _FailedRequest.URL;
if ([challenge.protectionSpace.host isEqualToString:baseURL.host]) {
[[challenge sender] useCredential:[NSURLCredential credentialForTrust:[protectionSpace serverTrust]] forAuthenticationChallenge:challenge];
} else if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate ]) {
NSString *path = [[NSBundle mainBundle] pathForResource:@&certificate& ofType:@&pfx&];
NSData *pfxdata = [NSData dataWithContentsOfFile:path];
CFDataRef inpfxdata = (__bridge_retained CFDataRef)
SecIdentityRef myI
SecTrustRef myT
OSStatus status = [self extractIdentityAndTrust:inpfxdata identity:&myIdentity trust:&myTrust];
SecCertificateRef myC
SecIdentityCopyCertificate(myIdentity, &myCertificate);
const void *certs[] = { myCertificate };
CFArrayRef certsArray = CFArrayCreate(NULL, certs, 1, NULL);
NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity certificates:(__bridge NSArray *)certsArray
persistence:NSURLCredentialPersistencePermanent];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
CFRelease(myIdentity);
CFRelease(myCertificate);
CFRelease(certsArray);
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}}-(OSStatus) extractIdentityAndTrust:(CFDataRef)inpfxdata identity:(SecIdentityRef *)identity trust:(SecTrustRef *)trust{
OSStatus securityError = errSecS
CFStringRef password = CFSTR(&pwd&);
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
securityError = SecPKCS12Import(inpfxdata, options, &items);
if (securityError == 0) {
CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex(items, 0);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemIdentity);
*identity = (SecIdentityRef)tempI
const void *tempTrust = NULL;
tempTrust = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemTrust);
*trust = (SecTrustRef)tempT
if (options) {
CFRelease(options);
return securityE}-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
_Authenticated = YES;
[connection cancel];
[self.webView loadRequest:_FailedRequest];}
搜尋相關Tags的文章:
本篇文章發表於 00:57
== 簽名檔 ==
/**程式設計也是設計一類設計講究的就是興趣或天份了,若無其中一個就不要免強自己踏入此行深淵!**/
目前尚無任何回覆
如要回應,請先.iOS开发之uiwebview双向https认证 - 推酷
iOS开发之uiwebview双向https认证
对于企业内部应用,很多时候会使用https进行数据加密传输,更有甚者,会使用双向证书加密
本屌丝的运维管理后台就是使用了双向证书加密的https,然而现在要把后台移植到手机上方便外出的时候值班
由于不是所有的同学都会app开发,但是好几个同学都会PHP的网页开发,因此这次开发APP将使用混合APP的方式,即是使用一个浏览器来打包一下后台的网站,外加一些其他功能进去,这样就方便了会PHP的同学协作开发各种功能了
下面是介绍一下如何使uiwebview支持https双向认证
直接上代码,解释在注释里
1.首先继承一个NSURLProtocal的子类,因为uiwebview的所有网络请求都会经过NSURLProtocal来处理的,因此https认证将在继承的NSURLProtocal里进行
这里先定义一个通用的证书验证类,因为我这里除了在uiwebview里面要双向验证证书外,还使用了ASIHTTPRequest来做某些后台接口请求
@interface opHttpsRequest : NSObject
+ (SecIdentityRef)identityWithT
+ (SecIdentityRef)identityWithC
+ (BOOL)extractIdentity:(SecIdentityRef *)outIdentity andTrust:(SecTrustRef*)outTrust fromPKCS12Data:(NSData *)inPKCS12D
+ (BOOL)identity:(SecIdentityRef *)outIdentity andCertificate:(SecCertificateRef*)outCert fromPKCS12Data:(NSData *)inPKCS12D
// // opHttpsRequest.m // opAssistant // // Created by kevin on 14-5-30. // Copyright (c) 2014年 BeeStudo. All rights reserved. //
#import &opHttpsRequest.h&
@implementation opHttpsRequest
+ (SecIdentityRef)identityWithTrust
SecIdentityRef identity = NULL;
SecTrustRef trust = NULL;
//绑定证书,证书放在Resources文件夹中
//NSData *PKCS12Data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@&yunwei& ofType:@&p12&]];//证书文件名和文件类型
NSData *PKCS12Data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@&yunwei& ofType:@&p12&]];//证书文件名和文件类型
if (!PKCS12Data) {
//没有文件证书
NSLog(@&Can not load pkcs12 cert , plz check !&);
//NSLog(@&pkcs12Data is %@&,PKCS12Data);
[[self class] extractIdentity:&identity andTrust:&trust fromPKCS12Data:PKCS12Data];
+ (SecIdentityRef)identityWithCert
NSString *path = [[NSBundle mainBundle]pathForResource:@&yunwei& ofType:@&p12&];
NSData *p12data = [NSData dataWithContentsOfFile:path];
SecIdentityRef identity = NULL;
SecCertificateRef certificate = NULL;
if (!p12data) {
//没有文件证书
NSLog(@&Can not load pkcs12 cert , plz check !&);
[[self class] identity:&identity andCertificate:&certificate fromPKCS12Data:p12data];
//NSArray *certArray = [NSArray arrayWithObject:(id)certificate];
//NSLog(@&cert array is %@&,certArray);
+ (BOOL)extractIdentity:(SecIdentityRef *)outIdentity andTrust:(SecTrustRef*)outTrust fromPKCS12Data:(NSData *)inPKCS12Data
OSStatus securityError = errSecS
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObject:@&1234& forKey:(__bridge id)kSecImportExportPassphrase];
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
securityError = SecPKCS12Import((__bridge CFDataRef)inPKCS12Data,(__bridge CFDictionaryRef)optionsDictionary,&items);
if (securityError == 0) {
CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemIdentity);
*outIdentity = (SecIdentityRef)tempI
const void *tempTrust = NULL;
tempTrust = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemTrust);
*outTrust = (SecTrustRef)tempT
NSLog(@&SSSSLLLL Failed with error code %d&,(int)securityError);
return NO;
return YES;
+ (BOOL)identity:(SecIdentityRef *)outIdentity andCertificate:(SecCertificateRef*)outCert fromPKCS12Data:(NSData *)inPKCS12Data
//NSLog(@&验证证书&);
OSStatus securityError = errSecS
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObject:@&1234& forKey:(__bridge id)kSecImportExportPassphrase];
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
securityError = SecPKCS12Import((__bridge CFDataRef)inPKCS12Data,(__bridge CFDictionaryRef)optionsDictionary,&items);
if (securityError == 0) {
CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemIdentity);
*outIdentity = (SecIdentityRef)tempI
const void *tempCert = NULL;
tempCert = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemCertChain);
*outCert = (SecCertificateRef)tempC
NSLog(@&SSSSLLLL Failed with error code %d&,(int)securityError);
return NO;
//NSLog(@&验证完毕&);
return YES;
这里再开始定义NSURLProtocal的子类
// // opURLProtocal.h // opAssistant // // Created by kevin on 14-5-29. // Copyright (c) 2014年 BeeStudo. All rights reserved. //
@interface opURLProtocal : NSURLProtocol
NSURLConnection *
NSMutableData *proRespD
// // opURLProtocal.m // opAssistant // // Created by kevin on 14-5-29. // Copyright (c) 2014年 BeeStudo. All rights reserved. //
#import &opURLProtocal.h&
#import &ASIHTTPRequest.h&
#import &toastView.h&
#import &opHttpsRequest.h&
#define kOpCenterAPI_url @&https://后台域名.com&
@implementation opURLProtocal
//可以在此定义数据容器,连接等
static NSString *cachingURLHeader = @&hadInURLProtocal&;
- (void)startLoading
//NSLog(@&1.start loading&);
//可以这样子拿到原来的请求,用以拼装自己的请求
NSMutableURLRequest *proxyRequest = [self.request mutableCopy];
//NSLog(@&protocal url is %@&,[[proxyRequest URL] absoluteString]);
[proxyRequest setValue:@&& forHTTPHeaderField:cachingURLHeader];
//connection = [NSURLConnection connectionWithRequest:proxyRequest delegate:self];
connection = [[NSURLConnection alloc] initWithRequest:proxyRequest delegate:self startImmediately:NO];
[connection start];
- (void)stopLoading
//请求在这里该结束了,在此终止自己的请求吧
//NSLog(@&stop it&);
[connection cancel];
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
//NSLog(@&2.in willSendRequest&);
if(response!=nil)
NSMutableURLRequest *redirectableRequest = [request mutableCopy];
[redirectableRequest setValue:nil forHTTPHeaderField:cachingURLHeader];
[self.client URLProtocol:self wasRedirectedToRequest:redirectableRequest redirectResponse:response];
return redirectableR
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
//NSLog(@&3.We are checking protection Space!&);
return YES;
if([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
//NSLog(@&Can Auth Secure Requestes!&);
return YES;
else if([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic])
//NSLog(@&Can Auth Basic Requestes!&);
return YES;
//return NO;
NSLog(@&Cannot Auth!&);
return NO;
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
// A CustomHTTPProtocol delegate callback, called when the protocol has an authenticate
// challenge that the delegate accepts via - customHTTPProtocol:canAuthenticateAgainstProtectionSpace:.
// In this specific case it's only called to handle server trust authentication challenges.
// It evaluates the trust based on both the global set of trusted anchors and the list of trusted
// anchors returned by the CredentialsManager.
//NSLog(@&4.!!!!!!!!!!!! didReceiveAuthenticationChallenge method&);
NSURLCredential *
assert(challenge != nil);
credential =
// Handle ServerTrust and Client Certificate challenges
NSString *authenticationMethod = [[challenge protectionSpace] authenticationMethod];
if ([authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
//NSLog(@&Trust Challange&);
SecTrustResultType trustResultT
err = SecTrustEvaluate(challenge.protectionSpace.serverTrust, &trustResultType);
//NSLog(@&SecTrustResult %u %d&,trustResultType, (int)err);
if (trustResultType == kSecTrustResultProceed || trustResultType == kSecTrustResultUnspecified) {
credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
assert(credential != nil);
//NSLog(@&self signed trust challange&);
credential = [NSURLCredential credentialWithIdentity:[opHttpsRequest identityWithCert] certificates:nil persistence:NSURLCredentialPersistencePermanent]; //到呢一步,certificates需要喺nil先过到
//NSLog(@&credential is %@&,credential);
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
//[protocol resolveAuthenticationChallenge:challenge withCredential:credential];
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
//这里是收到响应的头部信息,比如HTTP Header,可视情况做对self.client做相应操作,也可以不做处理
//NSLog(@&5.didReceiveResponse lalala&);
//NSLog(@&response is %@&,response);
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
//这几个不是Protocol的方法,是自发起的URLConnection的回调
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)sourceData
//NSLog(@&sourceData is %@&,sourceData);
//此方法会收到一部分或者全部的数据,可以这样子丢给原始请求的发起者
//NSLog(@&6.in didReceiveData method&);
if (proRespData == nil) {
proRespData = [sourceData mutableCopy];
[proRespData appendData:sourceData];
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
//和上一个方法类似,这里作为错误通知
//NSLog(@&7.1in didFailWithError method %@&,error);
[self.client URLProtocol:self didFailWithError:error];
//这里可以弹出一个错误提示
[toastView hideToast];
NSString *msg = [@&网络错误 - & stringByAppendingString:[error description]];
[toastView showToastWithOK:msg];
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
//自己的请求加载完成了,这样子可以通知self.client
//[self.client URLProtocolDidFinishLoading:self];
//NSString *proRespStr = [[NSString alloc] initWithData:proRespData encoding:1];
//NSData *sourceData = [NSData dataWithBase64EncodedString:proRespStr];
//NSLog(@&8.in connectionDidFinishLoading method&);
NSData *getData = proRespD
[self.client URLProtocol:self didLoadData:getData];
[self.client URLProtocolDidFinishLoading:self];
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
//根据request来决定要不要劫持
//需要特别注意的是,如果你用NSURLConnection来发起代理请求,那么那个代理请求的request也同样会经过这里来做判决,所以一定要判断是不是代理请求,然后返回NO
if ([request.URL.absoluteString rangeOfString:kOpCenterAPI_url].location != NSNotFound && [request valueForHTTPHeaderField:cachingURLHeader] == nil) return YES;
return NO;
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
//这里是干嘛的,我还没研究清楚,就简单的返回了原始值,有兴趣的话你可以研究一下
+ (BOOL)identity:(SecIdentityRef *)outIdentity andCertificate:(SecCertificateRef*)outCert fromPKCS12Data:(NSData *)inPKCS12Data
//NSLog(@&验证证书&);
OSStatus securityError = errSecS
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObject:@&1234& forKey:(id)kSecImportExportPassphrase];
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
securityError = SecPKCS12Import((CFDataRef)inPKCS12Data,(CFDictionaryRef)optionsDictionary,&items);
if (securityError == 0) {
CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemIdentity);
*outIdentity = (SecIdentityRef)tempI
const void *tempCert = NULL;
tempCert = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemCertChain);
*outCert = (SecCertificateRef)tempC
NSLog(@&SSSSLLLL Failed with error code %d&,(int)securityError);
return NO;
//NSLog(@&验证完毕&);
return YES;
2.在uiwebview的viewController里面,注册NSURLProtocal的实现是用哪个类
//这里用NSURLProtocal来截获连接 [NSURLProtocol registerClass:[opURLProtocal class]];
这样之后,所有匹配后台域名的请求在这个uiwebview里面都会进行了双向认证了
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致ios - How to call https url in uiwebview? - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.0 million programmers, just like you, helping each other.
J it only takes a minute:
I have an HTTPS url. It is loading in iPhone Safari, but didn't work in UIWebView.
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
How can I fix this problem?
2,46021735
I have explained below how to access https url in UIWebview it will help you clear the problem because it works for me.
Calling http is same as https url.
If, however, you're using a self-signed certificate, it's necessary to add some additional code.Because by default iOS will reject all untrusted https connections.
Restricting untrusted connections is very good default behaviour and any disabling of this is highly risky.So we will show an alert as we're going to bypass the default behaviour.
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionS
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)
These two above methods allows us to provide our own authentication mechanism for trusted connections
#import "ClassCon.h"
For now, I've hard coded the IP address of my trusted server.
#define TRUSTED_HOST @"192.168.1.2"
@implementation ClassCon {
NSMutableData *contentD
NSURLConnection *
-(void) loadContent {
contentData = [NSMutableData data];
NSString *contentURL = @"our url";
conn = [[NSURLConnection alloc] initWithRequest:
[NSURLRequest requestWithURL:[NSURL URLWithString:contentURL]] delegate:self];
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[contentData appendData:data];
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Bad: %@", [error description]);
ContentResponse *response = [[ContentResponse alloc]initWithRc:-999 andDescr:@"error" andAction:0];
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *loadedContent = [[NSString alloc] initWithData:
contentData encoding:NSUTF8StringEncoding];
NSLog(@"Loaded content: %@",loadedContent);
// ------------ ByPass ssl starts ----------
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:
(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust];
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge {
if (([challenge.protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust])) {
if ([challenge.protectionSpace.host isEqualToString:TRUSTED_HOST]) {
NSLog(@"Allowing bypass...");
NSURLCredential *credential = [NSURLCredential credentialForTrust:
challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential
forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
// -------------------ByPass ssl ends
Hope this helps
15.7k385146
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .25718
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 uiwebview支持https 的文章

 

随机推荐