我是ios / swift devel的新手。 我正在使用Alamofire通过以下代码获取数据:
let user = "abc"
let password = "def"
Alamofire.request(.GET, "https://wis.fit.vutbr.cz/FIT/st/get-courses.php")
.authenticate(user: user, password: password)
.responseJSON { response in
debugPrint(response)
}
但是,我一直收到这个错误:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
FAILURE: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “wis.fit.vutbr.cz” which could put your confidential information at risk." UserInfo={NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “wis.fit.vutbr.cz” which could put your confidential information at risk., NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, NSUnderlyingError=0x7974ccd0 {Error Domain=kCFErrorDomainCFNetwork Code=-1202 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9813, _kCFStreamErrorCodeKey=-9813, _kCFStreamErrorDomainKey=3, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x797faf00>, kCFStreamPropertySSLPeerCertificates=<CFArray 0x797f7580 [0x94f098]>{type = immutable, count = 2, values = (
0 : <cert(0x797f8930) s: wis.fit.vutbr.cz i: Brno University of Technology CA>
1 : <cert(0x797fa2a0) s: Brno University of Technology CA i: Brno University of Technology CA>
)}}}, _kCFStreamErrorCodeKey=-9813, NSErrorFailingURLStringKey=https://wis.fit.vutbr.cz/FIT/st/get-courses.php, NSErrorPeerCertificateChainKey=<CFArray 0x797f7580 [0x94f098]>{type = immutable, count = 2, values = (
0 : <cert(0x797f8930) s: wis.fit.vutbr.cz i: Brno University of Technology CA>
1 : <cert(0x797fa2a0) s: Brno University of Technology CA i: Brno University of Technology CA>
)}, NSErrorClientCertificateStateKey=0, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x797faf00>, NSErrorFailingURLKey=https://wis.fit.vutbr.cz/FIT/st/get-courses.php}
我也在Info.plist中关闭了ATS,因为它似乎是iOS 9.0上的常见问题。
即使我尝试从https://www.fit.vutbr.cz检索数据,也会收到此错误 有帮助吗?我完全迷失了。
答案 0 :(得分:1)
它未连接到NSAppTransportSecurity,
看起来这个网站有自签名或共享证书, iOS会拒绝请求,因为它无法验证证书, 如果您是该网站的管理员,那么 - 使用适当的证书, 如果有这个网站的“http”版本,你可以使用它, 否则您必须接受此证书,目前无法通过Alamofire获取,您可以查看此主题 - How to implement self signed certificates in Alamofire?