I am trying to do a .POST request with Alamofire in Swift 3. I´ve written the following function
func postToken(Token: String) {
let parameters : [String:Any] = ["api_key":"ivaomobileapp", "function":"login", "IVAOTOKEN=":"\(Token)"]
Alamofire.request("URL", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in
switch(response.result) {
case .success(_):
if let data = response.result.value{
print(data)
}
break
case .failure(_):
print(response.result.error as Any)
break
}
}
}
But the code doesn´t work, it gives the following error:
Alamofire.AFError.responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
This is the same request in CURL(UNIX)
curl https://whatever -X POST -F 'api_key=ivaomobileapp' -F 'function=Login' -F 'IVAOTOKEN=whatever'
What am I doing wrong?
Thanks