将curl转换为快速的alamofire发布请求

时间:2018-08-10 01:29:21

标签: ios swift curl

是否有人知道如何将下面的curl转换为快速的ios alamofre发布请求。谢谢

curl -X POST -H "Content-Type: application/json" -d '{"value1":"2","value2":"2","value3":"2"}' https://maker.ifttt.com/trigger/test/with/key/diljTtw5lkjq1dsklnTH0Jfw

1 个答案:

答案 0 :(得分:0)

我相信Alamofire代码是这样的:

let urlString = "https://maker.ifttt.com/trigger/test/with/key/diljTtw5lkjq1dsklnTH0Jfw"
let params = [
    "value1": 1,
    "value2": 2,
    "value3": 3
]
let headers = [
    "Content-Type": "application/json"
]

Alamofire.request(urlString, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
    if let json = response.result.value {
        print(json)
    }
}