如何在ruby中发送带身份验证的api请求

问题描述 投票:0回答:1

我有这个curl命令发送带身份验证的api请求。我正在使用空中编写测试,我需要在测试中发送api请求。卷曲命令

curl https://example.com/api/v2/tests.json \
  -v -u [email protected]:Abcd1234

我有如下测试,但我需要添加身份验证。我该怎么做?

describe 'Test to GET' do
  it 'should get the existing data'do
  get "https://example.com/api/v2/tests.json","[email protected]":"Abcd1234"
  expect_status(200)
  end
end
ruby-on-rails ruby api rest-client airborne
1个回答
3
投票

-u选项向客户端发送基本身份验证头。

Airborne的README顶部显示了如何发送auth标头:

describe 'Test to GET' do
  it 'should get the existing data' do
    get "https://example.com/api/v2/tests.json",
        { 'x-auth-token' => 'my_token' }
    expect_status(200)
  end
end

如何从user获取令牌:password对我将作为家庭作业离开(例如,你可能只是记录curl请求。)

您也可以通过Airborne config全局设置auth标头。

© www.soinside.com 2019 - 2024. All rights reserved.