最近在做push 信息到facebook中。当使用UIWebview加载https的站点时webview总是会报NSURLErrorDomain code=-1202,导致网页加载失败。自己打印错误和网上搜索是因为证书失效,https使用超文本安全传输协议,即超文本传输协议(HTTP)和SSL/TLS的组合,用以提供加密通讯及对网络服务器身份的鉴定。当我们的服务器使用自我签名证书时,而UIWebView不允许使用自签名证书,所以导致加载失败。我们可以使用NSURLConnection通过它的代理canAuthenticateAgainstProtectionSpace可以允许这种情况,从而通过它进行认证。
#import <UIKit/UIKit.h>
#import "MyObject.h"
@interface ViewController :UIViewController<UIWebViewDelegate,NSURLConnectionDelegate>
{
UIWebView *_web;
NSURLConnection *_urlConnection;
NSURLRequest *_request;
BOOL _authenticated;
}
@end
@interfaceViewController ()
@end
@implementation ViewController
@synthesize myobject;
- (void)viewDidLoad
{
[superviewDidLoad];
_web = [[UIWebViewalloc] initWithFrame:CGRectMake(0,0,768,1024)];
_web.delegate =self;