[已解決]網路請求HTTP load failed (kCFStreamErrorDomainSSL, -9802)
阿新 • • 發佈:2019-02-06
報錯:NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
do{
let str = try NSString (contentsOfURL:NSURL(string:"https://www.baidu.com")!,encoding:NSUTF8StringEncoding)
print(str)
}catch{
}
}
解決:
錯誤資訊:
1.NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
2.App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
錯誤原因:
iOS9中新增App Transport Security(簡稱ATS)特性, 主要使到原來請求的時候用到的HTTP,都轉向TLS1.2協議進行傳輸。這也意味著所有的HTTP協議都強制使用了HTTPS協議進行傳輸。
解決方案:
在Info.plist新增一段用於控制ATS的配置: