0

i am trying to implement post request with encoded parameters but its not working. the request on postman is looking like this

enter image description here

i am trying with this code

let params = [ "PIDNO":self.defaults.value(forKey: "pidno") as? String ?? "" ,
                     "GENDER":self.gender!,
                     "TENANTNAME":self.txtTenantName.text ?? "",
                     "EMAIL":self.txtEmailId.text ?? "",
                     "OFFPHONE":self.officeMobile.text ?? "",
                     "MOBILE":self.txtMobile.text ?? ""
            ] as [String : String]
        
        let url =  SharedInstance.sharedInstance.url+"UpdateTenantProfile/UpdateTenantProfiledetails?profileDetail="
                let headers: HTTPHeaders
                    headers = ["Content-type": "application/json"]
        AF.request(url,method: .post, parameters: params,encoding: JSONEncoding.default, headers: headers)
            .responseJSON { response in
                debugPrint(response)
                print(response.result)
            }

but on the server-side, I am getting null parameters

  • First encode your param to json string. [Check this][1] [1]: https://stackoverflow.com/questions/29625133/convert-dictionary-to-json-in-swift/29625483 Then create one more request dict using that encoded string like below and pass that in request param in Alamofire request param. let requestParam = ["profileDetails": **Encoded String**] – Dhaval Patel Mar 10 '21 at 15:38
  • no its not working because the encoded string i got is not matching to the required format, can you guide me which format i should encode because ASCII format is not working – Waqas Farooq Mar 11 '21 at 06:07
  • this is required encoded string so which format is this %7B%22PIDNO%22%3A%22CPA244%22%2C%22GENDER%22%3A%22M%22%2C%22TENANTNAME%22%3A%22Amlak+Al+Madina+Real+Estate%22%2C%22EMAIL%22%3A%22abdulla%40propertiesre.com%22%2C%22MOBILE%22%3A%220506262076%22%2C%22OFFPHONE%22%3A%22%22%7D – Waqas Farooq Mar 11 '21 at 06:09
  • user utf8 encoding formatter. – Dhaval Patel Mar 16 '21 at 02:41

0 Answers0