我有这个代码:
func loginWithBasicAuth() -> Void {
let usernameText = username.text
let passwordText = password.text
let credentialData = "\(usernameText):\(passwordText)".dataUsingEncoding(NSUTF8StringEncoding)
let base64Credentials = credentialData?.base64EncodedStringWithOptions([])
let headers = ["Authorization": "HTTP Basic \(base64Credentials)"]
Alamofire.request(.GET, "https://api.domainname.com/v0.1/", headers: headers).responseString { aResponse in
if let receivedString = aResponse.result.value {
print(receivedString)
} else {
print("Login failed.")
}
}
}
在控制台中打印:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) Login failed.
怎么了?
最佳答案
我不确定 NSThirdPartyExceptionAllowsInsecureHTTPLoads
是通过 HTTPS
连接时使用的正确 key 。您可能应该使用 NSThirdPartyExceptionMinimumTLSVersion
或 NSThirdPartyExceptionRequiresForwardSecrecy
。
我强烈建议阅读App Transport Security Technote文档,特别是诊断连接问题部分。
有一个工具可以帮助您诊断您的域:
/usr/bin/nscurl --ats-diagnostics [--verbose] URL
关于ios - 应用程序传输安全: NSURLSession/NSURLConnection HTTP load failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33238037/