ios - 将 IOS 应用程序连接到 asp.net API 时获得 ATS 失败的系统信任。错误代码 9813
问题描述
我有一个 IOS 应用程序和一个托管在同一网络上的 dot net API。我有一个 IP wxyz 我试图通过 info.plist 允许,因为它没有 SSL 证书。我知道不支持 IP 地址,所以我使用 xip.io 将其转换为域名。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>w.x.y.z.xip.io</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
我的斯威夫特代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = URL(string: "https://w.x.y.z.xip.io:44328/api/values/1")!
print("START")
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
print("DONE")
task.resume()
}
转到https://wxyzxip.io:44328/api/values/1在我的浏览器中完美运行。当我尝试运行它时,我得到
019-01-25 01:14:10.427331-0500 test_api[20555:3495649] ATS failed system trust
2019-01-25 01:14:10.427505-0500 test_api[20555:3495649] System Trust failed for [1:0x600000f8c900]
2019-01-25 01:14:10.427584-0500 test_api[20555:3495649] TIC SSL Trust Error [1:0x600000f8c900]: 3:0
2019-01-25 01:14:10.432453-0500 test_api[20555:3495649] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
2019-01-25 01:14:10.432601-0500 test_api[20555:3495649] Task <964CC4A4-C3C3-4349-80AA-E1DFC04920DA>.<1> HTTP load failed (error code: -1200 [3:-9802])
2019-01-25 01:14:10.433065-0500 test_api[20555:3495648] Task <964CC4A4-C3C3-4349-80AA-E1DFC04920DA>.<1> finished with error - code: -1200
解决方案
推荐阅读
- envoyproxy - envoy 配置解析错误 INVALID_ARGUMENT:Unexpected token
- html - 如何在标题的同一行添加按钮?
- python - Entrez eFetch 登录号
- android - 如何在两个活动之间传递 SimpleExoPlayer 实例?
- android - 在执行多个后台任务 Kotlin Coroutines 或 ThreadPool 时,哪种方法更好?
- kotlin - 使用 Kotlin 过滤列表并维护标题元素
- hadoop - 用于实时时间序列的新表的 Hbase 架构设计
- html - 溢出:滚动隐藏;具有绝对位置的属性在 Iphone 上不起作用
- python - 如何使用 lxml 获得带有子标签的所需标签?
- google-cloud-platform - 直接在谷歌存储桶中解压缩文件