Alamofire form-data” parameters type post request

360 views Asked by At

I am trying to make a request with form-data as in Postman, however I always get the "Parameters is invalid" response from the server. I tried with postman it works perfectly.

parameters: [String: String] = ["name": "name","email": "email"]

Here is my code:

     let request = AF
                .request(url, method: .post, parameters: parameters, encoder: URLEncodedFormParameterEncoder.default, interceptor: self.interceptor)
                .validate()
                .responseDecodable(of: KResult<T>.self) { response in
                    switch response.result {
                    case let .success(res):
                        print(res)
                        completion(.success(res.result))
                    case let .failure(error):
                        print(error)
                        completion(.error(error))
                        }
                }

PS

I looked at this question and many others in this website but didn't solve my problem

1

There are 1 answers

0
Ahmad On

The solution was to set the Content-Type key from application/json to

application/x-www-form-urlencoded