Search code examples
jsonswiftalamofire

I have A POST Request, Need to pass body parameters, In My Code Below


I have POST request that takes body as parameters.

enter image description here I tried this, but I didn't get any Response, Does Alamofire allow to Send body parameters when making API Requests?

 let params = [
            "course":"1",
            "batch":"1"
        ]


Alamofire.request(markURL, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { (response) in
            if((response.result.value) != nil) {
                var jsonVar = JSON(response.result.value!)
                print(jsonVar)
            }
        }

I'm Kinda stuck, Any help would be appreciated.


Solution

  • Change your encoding like this:

    Alamofire.request(markURL, method: .post, parameters: params, encoding: URLEncoding.httpBody, headers: headers).responseJSON { (response) in
                if((response.result.value) != nil) {
                    var jsonVar = JSON(response.result.value!)
                    print(jsonVar)
                }
            }