如何使用 ActionController::TestCase#post 使用具有 http 基本身份验证的 Rest API?
最佳答案
假设您使用的是 Rails 3,您可以通过调用 encoding_credentials 来设置请求环境 HTTP_AUTHORIZATION
在 ActionController::HttpAuthentication::Basic 中。
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials("username", "password")
关于ruby-on-rails - 如何使用 ActionController::TestCase#post 使用具有 http 基本身份验证的 Rest API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5437021/