我正在尝试转换此curl命令(有效):
curl https://address --user appID:appPassword -d grant_type=client_credentials -d scope=read -d format=json
一个快速的。
我已经有了,但我不知道如何传递我的appID和appPassword:
private func LoadKey() {
let params : Parameters = ["grant_type":"client_credentials",
"scope":"read",
"format":"json"]
let url = "https://address"
Alamofire.request(url, method: .post, parameters: params, encoding: URLEncoding.httpBody).response{ response in
print(response)
}
}
祝你有个美好的一天,并提前感谢你的回答。
首先将数据解析为dictionary
,使用.updateValue()
函数然后将它们解析为params,
var params : [String:String] = ["grant_type":"password",
"scope":"read",
"format":"json"]
params.updateValue("myPassword", forKey: "grant_type")
如果未找到密钥,则会创建具有该值的新密钥。