我正在尝试转换此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)
}
}
祝您有美好的一天,提前感谢您的回答。
最佳答案
首先将数据解析为字典
,使用.updateValue()
函数,然后将它们解析回参数,
var params : [String:String] = ["grant_type":"password",
"scope":"read",
"format":"json"]
params.updateValue("myPassword", forKey: "grant_type")
如果找不到该 key ,它将使用该值创建一个新 key 。
关于ios - 使用服务器用户名和密码在 swift 中发布方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54807461/