2017-09-22 137 views
0

我試圖讓一個alamofire POST請求,我送參數和主體,如下:額外的參數3

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是字符串類型)

回答

0

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 

} 
+0

和我在哪裏可以在這種情況下發送的身體嗎?如果我將編碼更改爲JSONEncoding.default? –

+0

將身體作爲參數傳遞,參數將是字典類型'[String:Any]' 。 –

+0

但我有一個參數類型的字典[字符串:任何],我應該發送身體也在參數?我試過了,它沒有工作,它應該發送到身體 –