如何使用Alamofire发布阵列。 Alamofire请求仅将字典类型作为参数:[String : Any]
。
但是我想将数组作为参数传递,而不是字典。
Alamofire.request(url, method: .post, parameters: [String : Any], encoding: JSONEncoding.default, headers: [:])
有什么办法解决它..?
var request = URLRequest(url: try! "your api".asURL())
request.httpMethod = "POST"
let arrParam = ["abc", "xyz"]
request.httpBody = try! JSONSerialization.data(withJSONObject: arrParam)
Alamofire.request(request).responseJSON { response in
switch (response.result) {
case .success:
//success code here
case .failure(let error):
//failure code here
}
}