【发布时间】:2018-05-31 09:47:44
【问题描述】:
我正在尝试使用 Alamofire 版本 3 和 Swift 3 发送以下数据。我得到的错误是 Extra argument method in call。
这是我到目前为止所做的:
struct userGoalServerConnection {
let WeightsUserGoal_POST = "http://api.umchtech.com:3000/AddWeightsGoal"
}
struct wieghtsUserGoal {
let id : Int
let token : String
let data : [ String : String ]
}
func syncInitialUserGaolValuesWithServer (userID : Int , userToken : String ){
let serverConnection = userGoalServerConnection()
let weightValue = wieghtsUserGoal.init(id: userID,
token: userToken,
data: ["weight_initial":"11","weight_end":"11","weight_difference":"11","calories_deficit":"11","difficulties":"11","weight_loss_week":"11","start_date":"2016-12-12","end_date":"2016-12-23","days_needed":"11"])
Alamofire.request(userGoalServerConnection.WeightsUserGoal_POST, method:.post, parameters: weightValue, encoding: JSONEncoding.default, headers:nil).responseJSON { response in
print(response.request as Any) // original URL request
print(response.response as Any) // URL response
print(response.result.value as Any) // result of response serialization
}
我对此很陌生,所以请不要介意我的问题是否有点太菜鸟。我在这里遇到了类似的问题,但他们并没有帮助我弄清楚我在哪里犯了错误:)
【问题讨论】:
-
您在请求中将
weightValue作为 post 参数传递,它不可能。如果您使用的是JSONEncoding,则传递Parameters对象的类型。