ios - NSURLConnection 以错误 1200 结束,现在是 1202?
问题描述
我所有的 api 调用都运行良好,但升级Xcode
到最新版本Xcode 9.4.1
后,我的 api 调用都不起作用。
我第一次收到NSURLConnection finished with error - code -1200
,但在添加后:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
到了info.plist
,我现在收到了NSURLConnection finished with error - code -1202
。SSL Certificate
我通过手动连接并检查(A+)确认我正在连接的域没有问题。
这是我用于加载图像的代码:
if let pictureUrl = URL(string: url) {
do {
let data = try Data(contentsOf: pictureUrl)
img.image = UIImage(data: data)
if let imageWidth = (img.image?.size.width) {
let height = width / imageWidth * (img.image?.size.height)!
conHeight.constant = height
}
}
catch let error {
print("Error \(error.localizedDescription)")
}
}
解决方案
写入setenv("CFNETWORK_DIAGNOSTICS", "3", 1)
后:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
正如@Jack 建议的那样,我解决了这个问题。我有与Charles
跑步有关的错误。关闭 Charles 后,我的 api 调用现在可以工作了。我可能只需要更新正在使用的SSL Certificate
,Charles
因为error 1202
是 SSL 证书错误。
推荐阅读
- c# - 使 Json.Net 将布尔值序列化为字符串
- go - 如何使用 Go 编程语言对文件名进行排序?
- react-native - 错误:缺少 app.json。请参阅 https://docs.expo.io/ 错误 Expo 最低限度的工作流程
- r - 从逗号分隔文本到矢量
- workbox - Workbox 4.1 backgroundSync:队列和插件
- python - Lotus Notes 首次设置禁用弹出窗口
- javascript - 如何将每个人从某个角色转移到一个频道
- android - registerResGeneratingTask 已弃用,使用 registerGeneratedResFolders(FileCollection)
- html - 使用 flex 来对齐已经有 flex 的项目?
- android - 解析 Android SDK 嵌套的 saveInBackground 不起作用