UIWebView 로드 https

1696 단어
UIWebView가 HTTPS를 로드할 때 - (void) webView: (UIWebView*) webView didFailLoadWithError: (NSError*) error {NSLog (@ "error =% @", error);
} error = Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “123.xx.xx.4” which could put your confidential information at risk."UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?,_kCFStreamErrorDomainKey=3,_kCFStreamErrorCodeKey=-9813, NSErrorPeerCertificateChainKey=(""이유: https ssl 인증서가 신뢰할 수 없음 해결 방법: UIWebView 로드 시 인증서 무시
-(void)createWebView{
       self.tishiWeb = [[UIWebView alloc]init];
      _tishiWeb.delegate=self;
      NSString *encodedString = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
      NSURL *url = [NSURL URLWithString:encodedString];
      _request = [NSURLRequest requestWithURL:url];
      [NSURLConnection connectionWithRequest:_request delegate:self];
      [self.view addSubview:_tishiWeb];
}

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
        if ([challenge previousFailureCount]== 0) {
                NSURLCredential* cre = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
                [challenge.sender useCredential:cre forAuthenticationChallenge:challenge];
            }
}


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
        [self.tishiWeb loadRequest:_request];
        [connection cancel];
}

좋은 웹페이지 즐겨찾기