iOS webview ssl 连接(kCFStreamErrorDomainSSL,-9843)

标签 ios objective-c ssl webview https

iOS9.3 xcode7.3.1 我想使用 WebView 访问 HTTPS 站点,出现错误(kCFStreamErrorDomainSSL, -9843)

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://52.197.95.84/ResonaIgonWeb/index.html"]];
request.allowsCellularAccess = YES;
request.timeoutInterval = 7.0;
self.myWebview.delegate = self;
self.myWebview.scrollView.showsHorizontalScrollIndicator = NO;
self.myWebview.scrollView.showsVerticalScrollIndicator = NO;
self.myWebview.scrollView.backgroundColor = [UIColor whiteColor];
[self.myWebview loadRequest:request];

当我实现代理的时候

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
 {
    NSString* str = request.URL.scheme;
    if ([str isEqualToString:@"https"]) {
        if (isOK == NO) {
            originrequest = request;
            NSURLSessionConfiguration* con = [NSURLSessionConfiguration defaultSessionConfiguration];
            con.requestCachePolicy = NSURLRequestUseProtocolCachePolicy;
            NSURLSession* urlsession = [NSURLSession sessionWithConfiguration:con delegate:self delegateQueue:[NSOperationQueue mainQueue]];
            task = [urlsession dataTaskWithRequest:request completionHandler:^(NSData* _Nullable data, NSURLResponse* _Nullable response, NSError* _Nullable error) {
                NSString* str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                NSLog(@"%@", str);
            }];
            [task resume];
            [webView stopLoading];
            return NO;
        }
    }
return YES;
 }

我已经在info.list中添加了

<key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    </dict>

有没有什么办法可以用HTML在服务器上显示XX webView? 请帮助我!

最佳答案

试试这个

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>insecure.example.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

关于iOS webview ssl 连接(kCFStreamErrorDomainSSL,-9843),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473596/

相关文章:

ios - 等边距布局 UICollectionViewCells

ios - Swift:在动画期间中途更改 UIImageView 图像

android - 在我的应用程序中导入原始文件( keystore )

ssl - 如何为 rabbitmq 添加密码套件支持?

ios - 从 iPhone 上的弹出 View Controller 传回数据

ios - 仅当另一个功能完成时才继续执行另一个功能 iOS Swift

objective-c - "Prepare Content"NSArrayController 设置已关闭 : how to fetch the content?

objective-c - 获取当前系统时间?

ios - 使用 KIF 以编程方式将点击事件发送到 iOS 中的后台坐标

python - 为 Python 2.6 添加 SSL 支持