如何使用ActionController :: TestCase#post来使用带有http basic auth的Rest API?

时间:2011-03-25 19:10:34

标签: ruby-on-rails ruby http testing rest

如何使用ActionController :: TestCase#post来使用带有http basic auth的Rest API?

1 个答案:

答案 0 :(得分:1)

假设您使用的是Rails 3,您可以通过调用ActionController :: HttpAuthentication :: Basic中的encoding_credentials来设置请求env HTTP_AUTHORIZATION

@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials("username", "password")