使用Alamofire的cURL请求

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