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
The solution was to set the
Content-Type
key fromapplication/json
toapplication/x-www-form-urlencoded