我正在尝试使用rest-client向REST服务(具体来说是HP ALM 11 REST API)发送请求,但一直收到未经授权的响应。可能是因为我没有正确遵循文档,但我也不确定自己是否正确设置了头部信息。到目前为止,我在搜索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问题,我也尝试了以下内容,但没有成功:
@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 Authorization: Basic ABCDE123
服务器验证基本身份验证头,创建一个新的LW-SSO令牌,并将其作为LWSSO_COOKIE_KEY返回。