Ios 使用Alamofire的cURL请求
我正在尝试使用Alamofire来完成此卷曲请求Ios 使用Alamofire的cURL请求,ios,swift,curl,alamofire,Ios,Swift,Curl,Alamofire,我正在尝试使用Alamofire来完成此卷曲请求 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' 这给了我一个状态400 我做错了什么 提前
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'
这给了我一个状态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)
}
非常感谢你!我必须将
.POST
更改为方法:.POST
并将.JSON
更改为.jsonecoding.default
以使其与Alamofire 4.8.0/Swift 9.4.1配合使用:Alamofire.request(“https://api.lyft.com/oauth/token,方法:.post,参数:params,编码:JSONEncoding.default,头:头)。身份验证(用户:“clientID”,密码:“clientSecret”).responseJSON{response in debugPrint(response)}
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)
}