【发布时间】:2016-02-11 06:24:17
【问题描述】:
按照此页面 (https://django-oauth-toolkit.readthedocs.org/en/latest/rest-framework/getting_started.html),我能够为我的 django 项目设置 OAuth。
以下 curl 命令为我提供了访问资源的令牌。
curl -X POST
-d "grant_type=password&username=<user_name>&password=<password>"
-u"<client_id>:<client_secret>" http://localhost:8000/o/token/
但是,当我使用 Alamofire 发送请求时,事情有点奇怪。这是我的代码
Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON)
.authenticate(user: client_ID, password: client_Secret)
其中参数是字典
[
"password": <password>,
"grant_type": password,
"username": <username>
]
使用 curl 命令,我可以从 Django 中看到 request.POST.items() 返回参数列表。但是,使用 Alamofire,什么都没有。参数出现在 request.body 中!
这个问题快把我逼疯了。任何帮助将不胜感激!
提前致谢。
【问题讨论】:
标签: ios django swift curl alamofire