【问题标题】:Swift curl --user postSwift curl --用户帖子
【发布时间】:2019-02-25 14:17:18
【问题描述】:

我有这个:

curl https://address --user appID:appKey -d grant_type=password -d scope=read -d format=json -d username="username" -d password="password"

我尝试快速转换它。你能帮帮我吗?

用户名和密码与appId和appKey

之间没有联系

我已经有了:

private func LoadKey() {
    var params : [String:String] = ["grant_type":"password",
                                    "scope":"read",
                                    "format":"json",
                                    "username":"myUsername",
                                    "password":"myPassword"]

    Alamofire.request(url, method: .post, encoding: JSONEncoding.default).responseJSON { (response) in
        print(response.result.value)
    }   
}

我不知道如何给出 appId 和 appKey

提前感谢您的回答,祝您有美好的一天。

【问题讨论】:

标签: ios swift web-services connection alamofire


【解决方案1】:

由于 curl 命令没有指定身份验证类型,我假设它是基本身份验证。如果是这样,请尝试以下操作:

private func LoadKey() {
    var params : [String:String] = ["grant_type":"password",
                                    "scope":"read",
                                    "format":"json",
                                    "username":"myUsername",
                                    "password":"myPassword"]

    Alamofire.request(url, method: .post, encoding: JSONEncoding.default)
                    .authenticate(user: "appID", password: "appKey")
                    .responseJSON { (response) in
                print(response)
            } 
}

最好, 卡斯滕

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-07
    相关资源
    最近更新 更多