我使用tastyPie 0.9.11來創建RESTful API。無法在curl中使用curl和ApiKeyAuthentication進行發佈
我得到的API工作正常,但後來當我添加APIKeyAuthentication我無法讓POST請求工作。
我已認證/授權在我的資源元爲:
authentication = ApiKeyAuthentication()
authorization= Authorization()
,我手動添加在管理網站用戶管理的API密鑰,密鑰1234567890
當我做一個得到它工作正常(http://127.0.0.1:8000/api/v1/application/?format=json &用戶名=管理員& API_KEY = 1234567890)
然而,當我嘗試使用curl做一個POST:
curl --dump-header - -H "Authorization: ApiKey admin:1234567890" -H "Content-Type: application/json" -X POST --data '{"user": "/api/v1/user/1/", "title":"api test application"}' http://localhost:8000/api/v1/application/
我收到401未授權錯誤。
我正在通過添加Authorization頭文件的文檔,但也許還有別的我做錯了?
更新:如果使用'curl --dump-header -H「Content-Type:application/json」-X POST --data'{「principle_investigator」:「/ api/v1/user/1 /「,」title「:」api測試應用程序「}'」http:// localhost:8000/api/v1/application /?username = admin&api_key = 1234567890「'但任何人都可以幫助我理解爲什麼標題選項不會'工作? – Ctrlspc