我正在尝试使用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)
}