seongju
seongju

Reputation: 487

Entering username and password for Alamofire request

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

The cURL command that ran successfully was

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

and it returned the correct JSON

for Alamofire I tried

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

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

and params is

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

but when I try it it says that

NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)

What am I doing incorrectly?

Upvotes: 3

Views: 2286

Answers (2)

seongju
seongju

Reputation: 487

Apparently there is a thing for this in Alamofire. 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 authenticate myself.

Upvotes: 7

Michal
Michal

Reputation: 15669

This error occurs when there is a problem with the certificate. My bets are that it is invalid. Unfortunately, Alamofire doesn't support overriding invalid certificates at the moment (like AFNetworking does for example).

Take a look at this thread for more details.

Upvotes: 1

Related Questions