Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra argument 'method' in call

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]

like image 953
CMA Avatar asked Sep 19 '16 11:09

CMA


5 Answers

I got the issue, I have to use JSONEncoding.default instead of .JSON, so the new syntax is

Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: JSONEncoding.default, headers: [:])
like image 120
CMA Avatar answered Oct 18 '22 08:10

CMA


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, the method is an extra argument

Go over that parameters again and make sure all is of correct type (Parameters?, ParameterEncoding, and HTTPHeaders)

like image 28
netdigger Avatar answered Oct 18 '22 07:10

netdigger


I was having the same issue, the problem is at parameters type, it should be of type [String: Any]. After I made this change, it worked for me.

 Alamofire.request(youUrl, method: .post, parameters: param as? [String: Any], encoding: JSONEncoding.default, headers: [:])
                .responseJSON { response in
like image 18
Xhulio Hasa Avatar answered Oct 18 '22 07:10

Xhulio Hasa


It means that some of the parameters type are wrong, check that you are sending these values:

url: String
method: HTTPMethod  (E.g: .post)
parameters: [String:Any]
encoding: ParameterEncoding  (E.g: JSONEncoding.default)
headers: [String: String]
like image 10
Andrea.Ferrando Avatar answered Oct 18 '22 08:10

Andrea.Ferrando


Updated for Swift 3:

let requestString = "https://thawing-inlet-46474.herokuapp.com/charge.php"
        let params = ["stripeToken": token.tokenId, "amount": "200", "currency": "usd", "description": "testRun"]

        Alamofire.request(requestString,method: .post, parameters: params, encoding: JSONEncoding.default, headers: [:]).responseJSON { (response:DataResponse<Any>) in

            switch(response.result) {
            case .success(_):
                if response.result.value != nil{
                    print("response : \(response.result.value)")
                }
                break

            case .failure(_):
                print("Failure : \(response.result.error)")
                break

            }
        }
like image 10
Alvin George Avatar answered Oct 18 '22 06:10

Alvin George