即使我在Info.plist中允许,也无法从没有证书的网站读取txt文件时遇到此问题。
我的Swift代码如下:
let url = URL(string: "http://newskit.matsworld.io/domaci/text.txt")!
let task = URLSession.shared.downloadTask(with: url) { localURL, urlResponse, error in
if let localURL = localURL {
if let string = try? String(contentsOf: localURL) {
print(string)
}
}
}
task.resume()
Info.plist看起来像这样:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>http://newskit.matsworld.io</key>
<dict>
<key>ExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>IncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
我对此一无所知,无法解决。感谢您的帮助!
答案 0 :(得分:0)
如果指定了domain
,则http
键应该只是没有方案(IncludesSubdomains
)和没有子域的域
<key>matsworld.io</key>