Entering username and password to request Alamofire

I'm trying to use Alamofire to make a GET request for my iOS app, but I really don't know how to enter my username and password.

The cURL command ran successfully:

curl -k -u user: pw https: // url / cli / method

and it returned correct JSON

for Alamofire I tried

Alamofire.request(.GET, self.baseURL + method, parameters: params).responseJSON { (_, _, JSON, _) in
            println(JSON)

      

where method baseURL + https: // url / rest / method

and params

let params = [
            "username" : self.username.text,
            "password" : self.password.text
        ]

      

but when i try it says that

NSURLConnection / CFURLConnection HTTP Load Error (kCFStreamErrorDomainSSL, -9813)

What am I doing wrong?

+3


source to share


2 answers


Apparently Alamofire has something for this. I need to do...

Alamofire.request(.GET, self.baseURL + method, parameters: nil)
    .authenticate(user: self.username.text, password: self.password.text)
    .responseJSON { (_, _, JSON, _) in
        println(JSON) 
}

      



To get authenticated.

+4


source


This error occurs when there is a problem with the certificate. My bets are that they are not valid. Unfortunately Alamofire does not currently support invalid certificate revocation (e.g. AFNetworking).



Check out this thread for more details.

+1


source







All Articles