我正在尝试使用 rest-client 向 REST 服务(HP ALM 11 REST API fwiw)发布请求并不断收到未经授权的响应。可能是我没有正确遵循文档,但我也不确定我是否正确地处理了标题。到目前为止,我对 RestClient 的谷歌搜索一直没有结果。任何帮助,将不胜感激:
代码:
@alm_url = "http://alm_url/qcbin/"
@user_name = "username"
@user_password = "password"
authentication_url = @alm_url + "rest/is-authenticate"
resource = RestClient::Resource.new authentication_url
resource.head :Authorization => Base64.encode64(@user_name) + ":" + Base64.encode64(@user_password)
response = resource.get
#response = RestClient.get authentication_url, :authorization => @username, @user_password
Rails.logger.debug response.inspect
基于这个SO question,我还尝试了以下操作但没有成功:
@alm_url = "http://alm_url/qcbin/"
@user_name = "username"
@user_password = "password"
authentication_url = @alm_url + "rest/is-authenticate"
resource = RestClient::Resource.new authentication_url, {:user => @user_name, :password => @user_password}
response = resource.get
#response = RestClient.get authentication_url, :authorization => @username, @user_password
Rails.logger.debug response.inspect
文档:
客户端将有效的基本身份验证标头发送到身份验证点。
GET /qcbin/authentication-point/authenticate 授权:基本 ABCDE123
服务器验证基本身份验证标头,创建新的 LW-SSO 令牌并将其作为 LWSSO_COOKIE_KEY 返回。