OGeek|极客世界-中国程序员成长平台

标题: iOS webview ssl 连接 (kCFStreamErrorDomainSSL, -9843) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:00
标题: iOS webview ssl 连接 (kCFStreamErrorDomainSSL, -9843)

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)webViewUIWebView*)webView shouldStartLoadWithRequestNSURLRequest*)request navigationTypeUIWebViewNavigationType)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? 请帮帮我!



Best Answer-推荐答案


试试这个

<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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4