Extra argument 'method' in call

前端 未结 15 1686
你的背包
你的背包 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:40
    Alamofire.request(url, method: .post, parameters: parameters, encoding: 
    JSONEncoding.default, headers: [:]).responseJSON 
    { response in
    
                switch (response.result) {
                case .success:
                    print(response)
                    break
                case .failure:
                    print(Error.self)
                }
            }
    
    0 讨论(0)
  • 2020-12-16 09:44

    I was facing same problem And try with all answer as previously post here, And then I got the solution and reason of this problem .

    This is happened due to pass the wrong object parse in the request, and finally the solution --

    theJSONText -- JSON string

    urlStr -- URL string

     let urlEncoadedJson = theJSONText.addingPercentEncoding(withAllowedCharacters:.urlHostAllowed)
        let urls = NSURL(string:"urlStr\(urlEncoadedJson ?? "")")
    
    let method: HTTPMethod = .get
    
    Alamofire.request(urls! as URL, method: method, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in
    
            switch(response.result) {
            case .success(_):
    
                if response.result.value != nil
                { 
                  // write your code here
                }
                break
    
            case .failure(_):
                if response.result.error != nil
                {
                    print(response.result.error!) 
                }
                break
            }
    
        }
    

    Note - There is no param in my URL .

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

    This is a family of functions that are very similar, which makes the compiler think you're trying to use a different function. Double check that ALL of the arguments you're supplying are the CORRECT TYPE that is expected. For example I was passing [String:Any] for the variant with headers, which expected [String:String] and got the same error.

    0 讨论(0)
提交回复
热议问题