关注此页(https://django-oauth-toolkit.readthedocs.org/en/latest/rest-framework/getting_started.html),我能够为我的django项目设置OAuth。Curl -d to Alamofire
以下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中!
这个问题让我发疯。任何帮助将不胜感激!
在此先感谢。
非常感谢!我昨晚想到了,现在事情进展顺利! – Yinan