如何使用alamofire发出此HTTP Post请求



如何在给定的样本中使用alamofire?

curl -X POST "http://localhost:2202/api/project" -H "接受: 应用程序/json" -H "key: David" -H "内容类型: 多部分/表单数据" -F "project={"title":"测试 标题","说明":"新测试说明 项目","优先级":假,"category_id":1,"location_id":1}">

let url = "192.168.1.1/api/project"
var header = [String:String]()
header["accept"] = "aplication/json"
header["key"] = "David"
let reqParam = ["project":["title":"Test Title","description":"Test description for new project","priority":false,"category_id":1,"location_id":1]]
Alamofire.upload(multipartFormData: { multipartFormData in
    for (key, value) in reqParam{
        do{
            let data = try JSONSerialization.data(withJSONObject: value, options: .prettyPrinted)
             multipartFormData.append(data, withName: key)
        }catch(let err){
            print(err.localizedDescription)
        }
    }
},usingThreshold:UInt64.init(),
  to: url,
  method: .post,
  headers: ["Content-Type": "multipart/form-data"],
  encodingCompletion: { (result) in
})

相关内容

  • 没有找到相关文章

最新更新