问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/31434008/entering-username-and-password-for-alamofire-request