3

I want to use Alamofire to send parameter and body both. I have seen tutorials and read QA where people use parameters to use as body too as in this one:

let parameters: Parameters = [
            "fullName": fullName,
            "mobileNumber": mobileNumber,
            "password": password
        ]
Alamofire.request(requestAddress , method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: header).responseJSON { response in
// utility
}

I am not sure how I should send body not using parameters as I need to send both parameters and body both.

  • I think you need to construct yourself the `URL` containing the parameters. With `QueryItems` it should be doable (see there: https://stackoverflow.com/questions/47932235/urlcomponents-queryitems-losing-percent-encoding-when-mutated) – Larme Sep 20 '18 at 10:50
  • Why do you need to pass the body actually where you can pass header, parameters even image-data for multipart? – Ankit Jayaswal Sep 20 '18 at 14:30

1 Answers1

0

You can either pass your request body with Parameters or as Data with a URLRequest object. My guess is that you can't make it happen both. If you also like to pass over some information as queryString parameters you can do it by setting them in a URLRequest like in this answer.

urlRequest.setValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")
Mert Ozdal
  • 82
  • 5