zoukankan      html  css  js  c++  java
  • WebView loadRequest请求错误"NSURLConnection finished with error

    执行下面代码

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.bing.com"]]];

    webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error打印出来的的错误如下

    1 [6587:75627] NSURLConnection finished with error - code -1022
    2 [6587:75574] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy 
    3 requires the use of a secure connection." UserInfo={NSUnderlyingError=0x600000641f50 
    4 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires 
    5 the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=http://www.bing.com/, 
    6 NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.,
    7  NSErrorFailingURLKey=http://www.bing.com/}}, NSErrorFailingURLStringKey=http://www.bing.com/, NSErrorFailingURLKey=http://www.bing.com/, 
    8 NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

    解决方案很简单:

    URLString必须使用https的请求webview就能正常显示了

    但后来发现要加载http://localhost:8080然后悲剧了,看来还是要研究一下具体机制了,在XCode 9就会出现错误中提示了很明显的信息

    The resource could not be loaded because the App Transport Security policy 

    去百度一下ATS policy,就可以知道很详细的答案了,在SupportFiles->info.plist文件里面添加下面属性就好了,有直接的选项,不需要自己填写

    done!

  • 相关阅读:
    ovs tag
    从数据库分析OpenStack创建虚机流程
    Neutron中的二层网络服务架构
    Failed to bind port
    OpenStack网络参数segment
    OpenStack与SDN控制器的集成
    HDU 3709 Balanced Number
    HDU 5787 K-wolf Number
    HDU 5803 Zhu’s Math Problem
    CodeForces 258B Little Elephant and Elections
  • 原文地址:https://www.cnblogs.com/zhouhui231/p/8572705.html
Copyright © 2011-2022 走看看