Dr. Arash Dr. Arash - 3 years ago 230
iOS Question

Swift - How to send POST request with "x-www-form-urlencoded" content-type

I searched so much and there's no clear instruction for sending POST request with "x-www-form-urlencoded" content-type.
i want to know how to do that and if you know how to do it with Alamofire it would be a better way.
any help will be appreciated.

Answer Source

Hope u are searching for this one or give us more explanation in code so we get it easily

let headers = [
                "Content-Type": "application/x-www-form-urlencoded"
            ]
        let parameters = [

            ]

        Alamofire.request("urlString", method: .post, parameters: parameters, encoding:  URLEncoding.httpBody, headers: headers).responseJSON { (response:DataResponse<Any>) in

            switch(response.result) {
            case.success(let data):
                print("success",data)
           case.failure(let error):
                print("Not Success",error)
                self.view.makeToast(message: "Server Error!!")
            }

        }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download