I'm working on Alamofire and I am trying to post a request to the server like this:
func sendRequest () {
print("fire now----------------------------------------------")
let parameters: Parameters = ["user": "001", "name": "josh"]
print(parameters)
let a = Alamofire.request("http://120.77.252.96:8388/", method: .get, parameters: parameters, encoding: URLEncoding.default).validate(statusCode: 200..<500).responseJSON(completionHandler: {responds in
switch responds.result {
case .success(let value):
let json = JSON(value)
print("JSON: \(json)")
case .failure(let error):
print(error)
}}
)
print(a)
}
But I constantly get errors like this:
Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(500)
and when I check the server side, it seems that the body of the request is empty.
Can anyone help me with this? Thanks so much!
I had the same problem my friend and I resolved it by changing the status code from
validate(statusCode: 200..<500)
to
validate(statusCode: 200..<600)
I'm new to Alamofire so I cannot give you an explanation to why or how it works or what the error means.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With