rest-client gem: 401 未经授权使用令牌
rest-client gem: 401 unauthorized with token
我正在使用 rest-client gem 尝试为我的 API 创建一个 post。
The RestClient.post helper requires three arguments to pass headers like that: .post(url, params, headers). Have you tried something more like this?
RestClient.post('http://api.example.com/', {key: 'value'}, authorization: 'a2m...')
https://github.com/rest-client/rest-client/issues/339#issuecomment-71787018
我已遵循上述建议,但收到 RestClient::Unauthorized - 401 Unauthorized
回复。
我的代码:
RestClient.post "http://api.example-dev.com:7000/v1/resources", {key: 'value'}, :authorization => 'yyyyyyyy'
我使用下面的 curl 命令成功了,但上面的 RestClient.post 没有成功。卷曲成功:
curl -i -X POST -d 'test[key]=1234' -H "Authorization: Token token=yyyyyyyyyyyyyy" \ http://api.example-dev.com:7000/v1/resources
这应该产生与 curl 相同的请求:
`RestClient.post "http://api.example-dev.com:7000/v1/resources", {:test => {key: '1234'}}, :authorization => 'Token token=yyyyyyyyyyyyyy'`
我正在使用 rest-client gem 尝试为我的 API 创建一个 post。
The RestClient.post helper requires three arguments to pass headers like that: .post(url, params, headers). Have you tried something more like this?
RestClient.post('http://api.example.com/', {key: 'value'}, authorization: 'a2m...')
https://github.com/rest-client/rest-client/issues/339#issuecomment-71787018
我已遵循上述建议,但收到 RestClient::Unauthorized - 401 Unauthorized
回复。
我的代码:
RestClient.post "http://api.example-dev.com:7000/v1/resources", {key: 'value'}, :authorization => 'yyyyyyyy'
我使用下面的 curl 命令成功了,但上面的 RestClient.post 没有成功。卷曲成功:
curl -i -X POST -d 'test[key]=1234' -H "Authorization: Token token=yyyyyyyyyyyyyy" \ http://api.example-dev.com:7000/v1/resources
这应该产生与 curl 相同的请求:
`RestClient.post "http://api.example-dev.com:7000/v1/resources", {:test => {key: '1234'}}, :authorization => 'Token token=yyyyyyyyyyyyyy'`