gpt4 book ai didi

ios - 使用 Alamofire 的 cURL 请求

转载 作者:可可西里 更新时间:2023-11-01 01:37:01 25 4
gpt4 key购买 nike

我正在尝试使用 Alamofire 来完成这个 cURL 请求

curl -X POST -H "Content-Type: application/json" \
--user "<client_id>:<client_secret>" \
-d '{"grant_type": "client_credentials", "scope": "public"}' \
'https://api.lyft.com/oauth/token'

我目前有:

  let plainString = "clientID:clientSecret" as NSString
let plainData = plainString.dataUsingEncoding(NSUTF8StringEncoding)
let base64String = plainData?.base64EncodedStringWithOptions([])

let headers = [
"Authorization": "Basic \(base64String)",
"Content-Type": "application/json"
]

let params = [
"grant_type": "client_credentials",
"scope": "public"
]

Alamofire.request(.POST, "https://api.lyft.com/oauth/token", parameters: params, encoding: .JSON, headers: headers).responseJSON { response in
debugPrint(response)
}

这给我一个状态 400

我做错了什么?

提前致谢!

最佳答案

解决了,

必须使用.authenticate

Alamofire.request(.POST, "https://api.lyft.com/oauth/token", parameters: params, encoding: .JSON, headers: headers).authenticate(user: "clientID", password: "clientSecret").responseJSON { response in
debugPrint(response)
}

关于ios - 使用 Alamofire 的 cURL 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35966112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com