我正在迅速。我看到了类似的question,但对此没有答案,但another却使用了 objective-c 语言。
错误日志:
TIC SSL Trust Error [1:0x1c4168340]: 3:0
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9843)
Task <00FBDA7D-E906-4BE2-8862-0AD6CAF1A0D7>.<1> HTTP load failed (error code: -1202 [3:-9843])
Task <00FBDA7D-E906-4BE2-8862-0AD6CAF1A0D7>.<1> finished with error - code: -1202
error
屏幕截图:
最佳答案
这是Swift中链接答案的代码。 HTH。
class RequestHelper: NSObject, URLSessionDelegate {
func makeRequest(request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) ->() ) {
let sessionConfiguration = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
let task = session.dataTask(with: request) { data, response, error in
completionHandler(data, response, error)
}
task.resume()
}
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition,
URLCredential?) -> () ) {
guard
challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust,
challenge.protectionSpace.host == "yourdomain.com",
let trust = challenge.protectionSpace.serverTrust
else {
return
}
let credential = URLCredential(trust: trust)
completionHandler(.useCredential, credential)
}
}
关于ios - 即使在plist文件上添加了临时异常,xcode 9.3版ios 11中的HTTP加载也会失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50226246/