Reputation: 47
Alamofire.request(TWConstants.LoginUrl,
method: .post,
parameters: param as! [String : String],
encoding: JSONEncoding.default,
headers: TWNetworkManager.getHeaderUser(username, passwd: passwd) as? [String : String]).responseJSON
this is my post request. The error is coming as:
Extra argument 'method' in call
I am migrating my Alamofire version 3 to Alamofire version 4. I tried to look into documentation but nothing comes to help for me. could anybody help me in this?
Upvotes: 2
Views: 682
Reputation: 1
let parameter : [String : Any] = [
"auth" : [
"api_key" : "",
"user_token" : ""
],
"mobile" : mobileNoTF.text!
]
Alamofire.request("https://url", method:.post , parameters : parameter ,encoding: JSONEncoding.default)
.responseJSON { response in
DispatchQueue.main.async {
}
if((response.result.value) != nil) {
let swiftyJsonVar = JSON(response.result.value!)
// self.compalinListArray.removeAll()
print(swiftyJsonVar)
if status == "success"
{
} else if status == "unauthorized"
{
}else if status == "error"
{
//else error
}
}
}
}else {
//else error
}
Upvotes: 0
Reputation: 3939
According to this Alamofire issue:
this kind of error appears when one argument is of the wrong type and the Swift interpreter believes that you're wrongly using the function:
request(urlRequest: URLRequestConvertible)
That’s why the error says:
Extra argument 'method' in call
In your example the optional “param” parameter has to be of [String: Any]
type:
public typealias Parameters = [String: Any]
Upvotes: 0
Reputation: 4901
Swift 4 , Use this
params = [
"username" : "",
"password" : "" ]
Alamofire.request(url, method: .post, parameters: params, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
print(response.result.value)
}
Upvotes: 1