Search code examples
swiftalamofire

Pass token with post request using Alamofire


I'm new to iOS and I would like some direction on why my code isn't working. I'm trying to make a call to a url and pass a token and get the response. My response is coming back with a 404 status code.

let reverse = ["token": "831b21c47a7f7daee7d6e4e3fa11deaa"]

        let url =  "http://challenge.com"


        Alamofire.request(url, parameters: reverse).responseJSON { response in
            print(response.request)  // original URL request
            print(response.response) // HTTP URL response
            print(response.data)     // server data
            print(response.result)   // result of response serialization

            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
        }

Solution

  • Try bellow code:

    Alamofire.request(url, method: .get, parameters: reverse, encoding: JSONEncoding.default).responseString { response in
            print(response.request)  // original URL request
            print(response.response) // HTTP URL response
            print(response.data)     // server data
            print(response.result)   // result of response serialization
    
            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
        }