Tag Archives: kcferrodomaincfnetwork code 310

IOS WebView failed to load the web page. Error domain = kcferrodomaincfnetwork code = 310 “there was a problem communicating with the secure web proxy server (HTTPS). “

The error message
ErrorDomain =kCFErrorDomainCFNetwork Code=310 “Problem communicating with secure Web Proxy server (HTTPS).” The UserInfo = 0 x155e20e0 {_kCFStreamErrorCodeKey = – 2096, NSErrorFailingURLStringKey = https://api.leancloud.cn/1.1/batch/save, NSErrorFailingURLKey = https://api.leancloud.cn/1.1/batch/save, NSLocalizedDescription= Problem communicating with secure Web proxy server (HTTPS). , _kCFStreamErrorDomainKey = 4, NSLocalizedRecoverySuggestion = please check your proxy Settings. Please contact your system administrator for assistance with this issue. }
Load page error occurs when ios UIWebView loads HTTPS :Error Domain=NSURLErrorDomain Code=-1202 “This server’s certificate is invalid
In the case of such problems, first set the plIST file to allow true.
The following solutions
1. Declare it in the VC of the WebView

NSURLConnection *_urlConnection;

NSURLRequest *_request;

BOOL _authenticated;

2. Add the following methods to the VC of webView

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
    if (!_authenticated) {
        _authenticated =NO;
        _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
        _request = request; 
        [_urlConnection start];
        return NO;
    }
    return YES;
}
 
#pragma mark - NURLConnection delegate
 
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    if ([challenge previousFailureCount] == 0)
    {
        _authenticated = YES;
        NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
        [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
    } else
    {
        [[challenge sender] cancelAuthenticationChallenge:challenge];
    }
}
 
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    // remake a webview call now that authentication has passed ok.
    _authenticated = YES;
    [self.webView loadRequest:_request]; //  self.webView replace your webview
    // Cancel the URL connection otherwise we double up (webview + url connection, same url = no good!)
    [_urlConnection cancel];
}
 
// We use this method is to accept an untrusted site which unfortunately we need to do, as our PVM servers are self signed.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

And that should load the webView properly