2012-06-11 36 views
24

當我嘗試在我的ModelResource中使用authentication = ApiKeyAuthentication()時,我總是收到401響應。 我看着Django Tastypie: How to Authenticate with API Key,他使用get參數來解決他的問題。如果我嘗試使用get參數,它會提取用戶名,但不是api_key!用curl附加多個查詢字符串變量

這適用於瀏覽器

http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 

經由捲曲在終端發送確實

curl --dump-header - http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 

爲什麼使用捲曲和追加2個查詢字符串參數,如?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50做它時不拾取API_KEY參數只拾取第一個。這不正確嗎?

回答

75

在命令行中輸入&意味着在後臺運行上述命令(由於@Maccesch),因爲這個&被視爲新命令之後的任何內容。

嘗試將url包裹在引號中。

curl --dump-header - "http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50"

+3

你說得對,'&'表示在後臺運行前面的命令。之後的字符串被認爲是一個新的命令。 – Maccesch

+0

@Maccesch,歡呼,我有一種感覺,那就是當我在本地虛擬機上運行Apache Solr實例時。 – rockingskier

+0

@rockingskier,你救了我的命!用引號括起URL! –