http://json.org/ defines that JSON is built on two structures:
I couldn't find a way to make Alamofire work on a post request where the parameters are [Any], which is the format required by the endpoint I'm consuming.
The error message is actualy a bit deceiving because it states "Extra argument in 'method' call" while performing a Alamofire.request but the actual problem is that parameters value is non-conforming.
The parameter by the name of parameters
in Alamofire
expects [String: Any]
. If you want to send an Array
through Alamofire, you can define custom ParameterEncoding like this
struct CustomEncoding: ParameterEncoding {
var _httpBody: Data?
func encode(_ urlRequest: Alamofire.URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
var request = try URLEncoding().encode(urlRequest, with: parameters)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = _httpBody
return request
}
}
Then use it like this
let body = ... // 'Array' converted to 'Data'
Alamofire.request(...,
method: ...,
parameters: [:],
encoding: CustomEncoding(_httpBody: body),
headers: ...)