這個問題已經重複,我看到了許多不同的答案,但它並沒有爲我工作呢!我有一個服務器設置在軌道上的紅寶石。如何添加驗證頭讓curl命令請求資源?
curl -i -X POST -d 'member_id=123456789&access_code=password&device_id=1234567890' https://myserver/customer_authentication
規範說對資源要求:
The request requires an authorization header.
在這旁邊:
用戶的在線訪問
我通過終端的正常工作,並收到一個訪問令牌的第一個命令存儲在授權頭中的令牌將用於查找用戶。匿名用戶標識符也將用於查找客戶信息,並確保與訪問令牌關聯的客戶關聯。 例如:頭[「授權」] =「承載online_banking_access_token」
現在我試圖從服務器獲取數據,這在規範說的列表:
GET /org1/customers/:acid/accounts
這將返回用戶帳戶的JSON 。我已經使用了這些,但沒有爲我工作:
curl -H GET Authorization: "348129" https://myserver/api/org1/customers/:acid/accounts
curl –H GET "Authorization: Token 348129" https://myserver/api/org1/customers/:acid/accounts
這是在服務器上的代碼:
if @customer && authenticated_customer_matches_requested_customer
body = { accounts: array_of_account_hashes }
status_code = :ok
else
body = { error_message: 'Invalid access token' }.to_json
status_code = :unauthorized
end
我收到:
{"error_message":"Invalid access token"}
我想你已經離開了您的最新嘗試-X選項。 試試這個: 'curl -X GET -H「授權:令牌348129」「https:// myserver/api/org1/customers /:acid/accounts」' –
@AlifJamaluddin Thanks mate。這對我有效.. – Bernard
好的。我將在答案部分添加它。 –