Today, when loading the HTTPS Web site, you encounter errors such as the following. So I made some changes to the iOS embedded webview that I wrote before, and it was able to load the HTTP website into the HTTPS website,
Here are the errors that occurred when I loaded the HTTPS website.
Error
Nsurlconnection/cfurlconnection HTTP Load failed (Kcfstreamerrordomainssl,-9813)
HTTPS Hypertext Transfer Security Protocol (abbreviated: HTTPS, English: Hypertext Transfer Protocol Secure) is a combination of Hypertext Transfer Protocol and SSL/TLS.
The main idea of HTTPS is to create a secure channel on an unsecured network. and can be verified and trusted when the appropriate encryption package and server certificate are used. Provide reasonable protection against eavesdropping and inter-man attacks.
The trust inheritance for HTTPS is based on a certificate authority that is preinstalled in the browser (such as VeriSign, Microsoft, and so on) (meaning "I trust the certification authority to tell me that I should trust").
So. An HTTPS connection to a site can be trusted, assuming that the server builds its own HTTPS, which means that the HTTPS channel is built in a self-certified way, which is generally not trusted by the client. So we usually visit some https websites in the browser, there will be a prompt to ask if you continue.
This is also the case when using WebView to load HTTPS websites. In other words, we must set the site to be secure at the time of request, and continue to interview
So we need to first infer that the site is not an HTTPS site when WebView starts loading the page. If so, let him pause loading, first use
Nsurlconnection to visit the site and then authenticate, place the site as a trusted site.
Then load the request again with WebView.
#pragma mark-uiwebviewdelegate-(BOOL) WebView: (UIWebView *) Awebview shouldstartloadwithrequest: (Nsurlrequest *) Request Navigationtype: (uiwebviewnavigationtype) navigationtype{nsstring* scheme = [[Request URL] scheme]; NSLog (@ "scheme =%@", scheme); If the inference is not HTTPS if ([scheme Isequaltostring:https]) {//assumed to be https: then use Nsurlconnection to re-send the request. Thus in the process of the request it is the URL to be requested to do the trust processing. if (!self.isauthed) {originrequest = Request; nsurlconnection* conn = [[Nsurlconnection alloc] initwithrequest:request delegate:self]; [Conn start]; [Awebview stoploading]; return NO; }} [self reflashbuttonstate]; [Self freshloadingview:yes]; Nsurl *theurl = [request URL]; Self.currenurl = theURL; return YES;}
The trust issue is handled in the Nsurlconnection proxy method.
-(void) connection: (Nsurlconnection *) connection Willsendrequestforauthenticationchallenge: ( Nsurlauthenticationchallenge *) challenge{ if ([Challenge previousfailurecount]== 0) { _authed = YES; Nsurlcredential This class is an immutable object that represents an authentication credential. The actual type of the credential declares the constructor of the class to determine. nsurlcredential* cre = [nsurlcredential credentialForTrust:challenge.protectionSpace.serverTrust]; [Challenge.sender usecredential:cre forauthenticationchallenge:challenge]; } Else<pre name= "code" class= "OBJC" >
Finally, after receiving a response in the Nsurlconnection proxy method, use the Web view to load the HTTPS Web site again.
pragma mark ================= nsurlconnectiondatadelegate <nsurlconnectiondelegate>-(NSURLRequest *) Connection: (nsurlconnection *) connection willsendrequest: (nsurlrequest *) Request Redirectresponse: (Nsurlresponse *) response{ NSLog (@ "%@", request); return request; } -(void) connection: (Nsurlconnection *) connection didreceiveresponse: (Nsurlresponse *) response{ self.authed = YES ; WebView another load of the request. [WebView loadrequest:originrequest]; [Connection Cancel];}
Two recommended StackOverflow address:
Http://stackoverflow.com/questions/11573164/uiwebview-to-view-self-signed-websites-no-private-api-not-nsurlconnection-i
Http://stackoverflow.com/questions/20365774/call-https-url-in-uiwebview
demo:https://github.com/wsq724439564/https--
IOS UIWebView loading HTTPS Web site appears nsurlconnection/cfurlconnection HTTP load failed (KCFSTREAMERRORDOMAINSSL,