我正在尝试发送以下 JSON 数据。我正在使用 Alamofire 4.0。 如何以form-data格式向服务器传递Data?
{
"apikey" : "455feh54b",
"action": "ADD",
"address1" : "Mumbai",
"country" : "India"
"userInfo" : {
"user_detail" :[
{
"name" : "abc",
"age" : 15,
"location" : "Delhi"
},
{"name" : "pqr",
"age" : 20,
"location" : "Mumbai"
}
]
}
}
最佳答案
以下是简单发送的方法
let user_detail = ["name":name, "age":age, "location":location]
let userInfo = ["user_detail": user_detail]
let params = ["apikey":title,
"action":type,
"address":time,
"userInfo":String.JSONStringify(value: user_detail as AnyObject)]
Alamofire.request(url, method:.post, parameters: params, encoding: URLEncoding.default).validate().responseAuthJSON {
response in
switch response.result {
case .failure(let error):
print(error)
self.showAlert(title: "Saving note failed! Please, try again.", message: "")
case .success(let responseObject):
print("response is success: \(responseObject)")
}
}
关于ios - 如何使用 Alamofire 4.0 post 请求快速发送表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47069419/