I'm looking a lot of examples, mainly from @matt on the web but I can't get this work:
import Alamofire
extension Request {
public func debugLog() -> Self {
debugPrint(self)
return self
}
}
func login(userName: String, passWord: String) -> String {
let manager = Manager.sharedInstance
// Specifying the Headers we need
manager.session.configuration.HTTPAdditionalHeaders = [
"Content-Type": "application/json",
"User-Agent": "test",
"Cache-Control": "no-cache",
"Authorization": "apikey"
]
// When
let params =
["userName" : userName,
"passWord" : passWord]
Alamofire.request(.POST, Constants.apiURL.url + "users/login", parameters: params)
.validate()
.debugLog()
.responseJSON { responseRequest, responseResponse, responseResult in
NSLog(String(responseRequest)) // never enter here
NSLog(String(responseResponse))
NSLog(String(responseResult))
}
return ""
}
It never ever enter inside my block .responseJSON. Whatever I use as parameter, forcing an error or getting the perfect cURL command from debug, it never works.
My cURL is fine, I can execute it normally in the bash and I get a good json result.
curl -i \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Cache-Control: no-cache" \
-H "User-Agent: test" \
-H "Authorization: apikey" \
-H "Content-Type: application/json" \
-d "passWord=123&userName=123" \
"http://api.cc/users/login"