Я ищу много примеров, в основном от @matt в Интернете, но я не могу получить эту работу:
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 ""
}
Он никогда не входит в мой блок .responseJSON. Что бы я ни использовал в качестве параметра, вызывая ошибку или получая идеальную команду cURL от отладки, это никогда не работает.
Мой cURL в порядке, я могу нормально выполнить его в bash и получить хороший результат json.
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"
responseString- person Bannings   schedule 05.09.2015