Extra argument 'method' in call

前端 未结 15 1653
你的背包
你的背包 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: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) 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 .

提交回复
热议问题