api文档要求在使用用户名、密码进行授权后返回令牌。我添加了返回的令牌,但一直收到401响应。
下面是api文档中的curl请求:
curl \
-H "Authorization: Token token=\"be08f1f4-c315-4d59-9c7c-d7a8b45a7db5\""
-H "Accept: application/json" \
-H "Content-Type: application/json" \
https://something.fake/api/lists下面是我使用Rest::Client的代码:
RestClient::Request.execute(
method: post,
url: https://something.fake/api/lists,
:content_type => :json,
:accept => :json,
headers: {"Authorization" => "Token token=${token}"}
)我不确定我错过了什么。
发布于 2020-02-18 23:57:17
curl请求将令牌放在引号中。所以它不会是
token=be08f1f4-c315-4d59-9c7c-d7a8b45a7db5它将会是
token="be08f1f4-c315-4d59-9c7c-d7a8b45a7db5"所以你的代码需要是:
headers: {"Authorization" => "Token token=\"${token}\""}https://stackoverflow.com/questions/60276825
复制相似问题