如何在Ruby中通过身份验证发送API请求



我有此curl命令以身份验证发送API请求。我正在使用机载进行测试,需要在测试中发送API请求。curl命令

curl https://example.com/api/v2/tests.json 
  -v -u test@email.com:Abcd1234

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

describe 'Test to GET' do
  it 'should get the existing data'do
  get "https://example.com/api/v2/tests.json","test@email.com":"Abcd1234"
  expect_status(200)
  end
end

-u选项将基本的验证标头发送给客户端。

机载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

如何将令牌从 userpassword对我作为作业留给你(例如,您可以简单地记录curl请求。)

您还可以通过 airborne config。

最新更新