Extra argument 'method' in call

前端 未结 15 1684
你的背包
你的背包 2020-12-16 08:59

Getting error while calling Alamofire request method in the latest version(4.0.0).

The syntax is:

Alamofire.request(urlString,method: .post, parame         


        
相关标签:
15条回答
  • 2020-12-16 09:19

    Make sure your parameters is [String: Any]

    i.e

    let parameters = ["foo": "bar"]
    

    Not:

    let parameters : Parameter = ["foo": "bar"]
    
    0 讨论(0)
  • 2020-12-16 09:19

    Almofire methods changed in Swift 3 as the following:

    1. Reorder parameters (url then method type).
    2. Change Encoding Enum to be "JSONEncoding.default" for example.
    0 讨论(0)
  • 2020-12-16 09:20

    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. :-)

    0 讨论(0)
  • 2020-12-16 09:21

    just make sure all the parameters are in the correct format , most importantly the parameters must be in [String:Any] type array.

    0 讨论(0)
  • 2020-12-16 09:24

    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
    
    0 讨论(0)
  • 2020-12-16 09:25

    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: [:])
    
    0 讨论(0)
提交回复
热议问题