简体   繁体   中英

Alamofire HTTPS request not working for this website

I am new to ios/swift devel. I am using Alamofire to get data with following piece of code:

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)
    }

However, I keep getting this error:

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}

I've also turned off ATS in Info.plist since it seems to be a common problem on iOS 9.0.

I get this error even when I try to retrieve data from https://www.fit.vutbr.cz Any help? I am completely lost in this.

It is not connected to the NSAppTransportSecurity,

Looks like this website has either self-signed or shared certificate, iOS does rejects request because it can not verify the certificate, If you are admin of the website then - use proper certificate, If there is "http" version of this site , you could use that, otherwise you have to accept this certificate, which is not available via Alamofire at the moment, you can have a look at this topic - How to implement self signed certificates in Alamofire?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM