ios - 调用 alamofire swift 3 时的额外参数

标签 ios swift alamofire

我正在尝试发出 alamofire post 请求,我正在发送一个参数和一个正文,如下所示:

  static func sendFeedbackResultOldCustomer(customerId: String?,fbackAnswers:String? ,answers: String?, completion: @escaping (Bool , String?) ->() ){

        let parameters: Parameters = ["customer_id":customerId!,"customer_new":"0","x-session":getXSession()]
        request(urlString: APIStrings.feedbackSent, parameters: parameters, method: .post, headers: nil, encoding: answers, updateXsession: false) { (success, error, errorMsg, response) in
            if(success) {
                completion(true, nil)
            }
            else {
                completion(false, response?.result.error as? String)
            }
        }
    }

请求代码:

fileprivate static func request (urlString: String!, parameters: Parameters?, method: HTTPMethod, headers: HTTPHeaders?,encoding: String!, updateXsession: Bool, completion: @escaping(Bool, Error?, String?, DataResponse<Any>?) ->()) {
        Alamofire.request(urlString, method: method, parameters: parameters, headers: headers,encoding:encoding).responseJSON { (response) in// here is the error (extra argument method in call)
            let contentType = response.response?.allHeaderFields["X-Session"] as? String
            if (updateXsession)
            {
                UserDefaults.standard.set(contentType, forKey: "x-session")
            }

            let success = checkIfSuccess(response: response)
            if(success){
                completion(success, nil, nil, response)
            } else {
                completion(success, response.error, "Failed", nil)
            }
        }

在 alamofire 请求中,我收到以下错误:调用中存在额外参数。知道发生了什么吗?

正在发送的参数:

let parameters: Parameters = ["customer_id":customerId!,"customer_new":"0","x-session":getXSession()]

我正在尝试发送正文:

X_types = [{"type_id":"17","value":"3"},{"type_id":"12","value":"test"},{"type_id":"14","value":"4"},{"type_id":"19","value":"3"},{"type_id":"16","value":"4"},{"type_id":"13","value":"3"},{"type_id":"18","value":"4"},{"type_id":"15","value":"4"},{"type_id":"2","value":"4"},{"type_id":"11","value":"1"},{"type_id":"1","value":"3"},{"type_id":"8","value":"3"},{"type_id":"6","value":"2"},{"type_id":"4","value":"22-09-2017 - 12:1"},{"type_id":"5","value":"Test"}]

X_types 在编码中作为字符串发送(x_types 是字符串类型)

最佳答案

alamofire 请求的签名为:public func request(_ url: URLConvertible, method: Alamofire.HTTPMethod = default,parameters:Parameters? = default,encoding: ParameterEncoding = default, headers: HTTPHeaders? = default) 。我认为您的签名不匹配。

尝试

let request = Alamofire.request(url, method: HTTPMethod.post, parameters: params, encoding: JSONEncoding.default, headers: header)
request.responseJSON { response in 

}

关于ios - 调用 alamofire swift 3 时的额外参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46360534/

相关文章:

ios - 为什么swift5不支持导入文件的类型?

javascript - 获取 JSON 数据时遇到问题

ios - Alamofire DownloadRequest 验证并从服务器获取响应数据

iOS 使用嵌套请求加载表数据

ios - 使用 header 和参数发出 get 请求时出现 alamofire 499

iphone - ios 身份验证的最佳实践和教程

ios - 返回在 UIAlertControllerStyle.ActionSheet 中选择的 Action

iphone - 需要确认继承 UIAlertView 是合法的

objective-c - Objective-C : How to list set of locations with the nearest geolocation

arrays - 从数组生成网格