这个问题已经重复,我看到了许多不同的答案,但它并没有为我工作呢!我有一个服务器设置在轨道上的红宝石。如何添加验证头让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"}
2016-03-01
Bernard
+1
我想你已经离开了您的最新尝试-X选项。 试试这个: 'curl -X GET -H“授权:令牌348129”“https:// myserver/api/org1/customers /:acid/accounts”' –
+0
@AlifJamaluddin Thanks mate。这对我有效.. –
+0
好的。我将在答案部分添加它。 –