Getting error while calling Alamofire request method in the latest version(4.0.0).
The syntax is:
Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: .JSON, headers: [:])
the type of requestParam is [String:Any]
Getting error while calling Alamofire request method in the latest version(4.0.0).
The syntax is:
Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: .JSON, headers: [:])
the type of requestParam is [String:Any]
My problem was in optional parameters in the headers that were not unwrapped.
It means that some of the parameters type are wrong, check that you are sending these values:
You are getting that error because of the wrong data types.
Parameters Type should be [String : Any] and parameters type shouldn't be an optional.
Header Type should be [String : String] or nil and header type shouldn't be an optional as well.
Hope it helps. :-)
Make sure your
parameters
is [String: Any]i.e
Not:
I can only refer you to: https://github.com/Alamofire/Alamofire/issues/1508#issuecomment-246207682
Basically, if one of your parameters is of the wrong type, the swift compiler will assume you're using
request(urlRequest:URLRequestConvertible)
and then, themethod
is anextra argument
Go over that parameters again and make sure all is of correct type (
Parameters?
,ParameterEncoding
, andHTTPHeaders
)Updated for Swift 3: