首页 > 分享 > iOS webview无法加载网页 Error Domain=kCFErrorDomainCFNetwork Code=310“与安全 web 代理服务器 (HTTPS) 通信时出现问题。”

iOS webview无法加载网页 Error Domain=kCFErrorDomainCFNetwork Code=310“与安全 web 代理服务器 (HTTPS) 通信时出现问题。”

最新推荐文章于 2024-04-29 11:08:33 发布

莱莱莱莱星人 于 2019-04-12 17:41:35 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

错误信息

Error Domain=kCFErrorDomainCFNetwork Code=310 "与安全 web 代理服务器 (HTTPS) 通信时出现问题。" UserInfo=0x155e20e0 {_kCFStreamErrorCodeKey=-2096, NSErrorFailingURLStringKey=https://api.leancloud.cn/1.1/batch/save, NSErrorFailingURLKey=https://api.leancloud.cn/1.1/batch/save, NSLocalizedDescription=与安全 web 代理服务器 (HTTPS) 通信时出现问题。, _kCFStreamErrorDomainKey=4, NSLocalizedRecoverySuggestion=请检查您的代理设置。有关此问题的帮助,请联系您的系统管理员。}

ios UIWebView加载https出现 load page error:Error Domain=NSURLErrorDomain Code=-1202 "此服务器的证书无效

出现此类问题,先将plist文件中 allow Arbitrary Loads 设置为true。

以下解决办法

1.在webview的vc中 声明

NSURLConnection *_urlConnection;

NSURLRequest *_request;

BOOL _authenticated;

2.在webview的vc中加入以下方法

- (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替换成自己的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];

}

这样就可以正常加载webView了  

相关知识

【QT教程】QT6 Web开发入门 QT Web
xcode 报“Remote object proxy returned error: Error Domain=NSCocoaErrorDomain Code=4099 ”The connec...
「IOS 网络踩坑」错误 Error Domain=NSURLErrorDomain Code=
AFNetworking Error Domain Code=
AFNetWorking3.1 出现code=
彻底搞懂移动Web开发中的viewport与跨屏适配
风花雪月
【前端】VS Code 前端环境搭建教程
探索更快网页加载的秘诀:minimalcss —— 智能提取关键CSS的利器
web支付基础教程

网址: iOS webview无法加载网页 Error Domain=kCFErrorDomainCFNetwork Code=310“与安全 web 代理服务器 (HTTPS) 通信时出现问题。” https://m.huajiangbk.com/newsview1074109.html

所属分类:花卉
上一篇: 花牛苹果简单介绍
下一篇: Ltp介绍及实践(2020092