Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(500)

Tags:

alamofire

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!

like image 833
JoshJoshJosh Avatar asked Jan 18 '17 05:01

JoshJoshJosh


1 Answers

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.

like image 100
Cyril Avatar answered Sep 19 '22 14:09

Cyril