I am trying to make a HTTP Post using alamofire, below is my code:
@IBAction func loginUserBtn(_ sender: Any) {
let urlAddress = "http://xx.xx.xx.xx:xx/xx/xx/xx/login"
let pass = Array(userPassword.text!)
let username = userEmail.text!
let params : [String: Any] = ["username": username, "pwd": pass]
print(params)
let headers: HTTPHeaders = [
"Accept": "application/json",
"Content-Type": "application/json"
]
Alamofire.request(urlAddress, method: .post, parameters: params, encoding: URLEncoding.default, headers: headers).responseJSON{
responds in
if responds.result.isSuccess{
print("Succesfull")
let LoginJSON : JSON = JSON(responds.result.value!)
//self.updateWeatheData(json: weatherJSON)
print(LoginJSON)
}
else{
print("Error \(String(describing: responds.result.error))")
}
}
}
This is the error I'm getting but if I change responseJSON to responseString I get a success, but the server is rejecting my data.
Here is my error message:
Error Optional(Alamofire.AFError.responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})))
responseString
? – OOPer