NSURLSession/NSURLConnection 加载 web 视图时 HTTP 加载失败(kCFStreamErrorDomainSSL,-9814)?
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814) in Loading webview?
我有一个 url which domain.com/map.jsp 这是一个 JSP 页面,其中显示 google 带有自定义标记的地图一些 javascript 代码是 written.When 我在设备上加载此页面然后它显示错误 NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9814)。但它在 iOS 模拟器上运行良好。
我在 google 上搜索了很多相关内容,但没有解决方案。
1.Bye 传递 url
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2.Specifying url only.I 无法对 url 进行硬编码,因为 url 可以是动态的,所以下面的代码对我不起作用。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourdomain.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
3.I 在 mywebview class 中添加了以下方法,但调用了 none 个方法
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:
(NSURLProtectionSpace *)protectionSpace {
return YES;
}
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge {
if (([challenge.protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust])) {
if ([challenge.protectionSpace.host isEqualToString:@"mydomain.com"]) {
NSLog(@"Allowing bypass...");
NSURLCredential *credential = [NSURLCredential credentialForTrust:
challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential
forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
请提出为什么它不能在 iOS 设备上工作但在 simulator.What 上工作正常是解决方案吗?
我的 iPad.Firstly 的 date/time 设置有问题 我尝试在 iPad 上的 chrome 上打开 google.com 然后它显示不安全的网络 error.So 我更改了 iPad date/time 设置我的问题已解决。
我有一个 url which domain.com/map.jsp 这是一个 JSP 页面,其中显示 google 带有自定义标记的地图一些 javascript 代码是 written.When 我在设备上加载此页面然后它显示错误 NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9814)。但它在 iOS 模拟器上运行良好。
我在 google 上搜索了很多相关内容,但没有解决方案。
1.Bye 传递 url
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2.Specifying url only.I 无法对 url 进行硬编码,因为 url 可以是动态的,所以下面的代码对我不起作用。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourdomain.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
3.I 在 mywebview class 中添加了以下方法,但调用了 none 个方法
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:
(NSURLProtectionSpace *)protectionSpace {
return YES;
}
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge {
if (([challenge.protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust])) {
if ([challenge.protectionSpace.host isEqualToString:@"mydomain.com"]) {
NSLog(@"Allowing bypass...");
NSURLCredential *credential = [NSURLCredential credentialForTrust:
challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential
forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
请提出为什么它不能在 iOS 设备上工作但在 simulator.What 上工作正常是解决方案吗?
我的 iPad.Firstly 的 date/time 设置有问题 我尝试在 iPad 上的 chrome 上打开 google.com 然后它显示不安全的网络 error.So 我更改了 iPad date/time 设置我的问题已解决。