我試圖運行Django Rest Framework(鏈接測試)一些測試和重現此捲曲電話:在Django Rest Framework中測試,重現這個curl請求?
curl -X POST -d "grant_type=password&username=<user_name>&password=<password>"
http://<client_id>:<client_secret>@127.0.0.1:8000/v1/token/
這是我曾嘗試:
def test_oauth2_token_for_user(self):
"""
Test Django OAuth Toolkit and make a request for am access token.
"""
self.client.credentials(HTTP_AUTHORIZATION='grant_type ' + "password&username=<user_name>&password=<password")
response = self.client.post('/api/token/')
有人能告訴我從哪裏開始。我不確定如何發送標頭grant_type=password&username=<user_name>&password=<password>
並使用用戶名和密碼格式化網址。