Sto tentando di inviare una richiesta a un servizio REST (FWI API REST di HP ALM 11) utilizzando rest-client e continuando a ricevere la risposta non autorizzata. Potrebbe essere che non sto seguendo i documenti, ma anche io non sono sicuro di fare le intestazioni correttamente. Finora il mio googling per RestClient è stato infruttuoso. Qualsiasi aiuto sarebbe apprezzato:Come si esegue l'autorizzazione di base Rails con RestClient?
Codice:
@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
Sulla base di questo SO question Ho anche provato il seguente senza successo:
@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
Documentazione:
client invia una valida Intestazione di autenticazione di base per il punto di autenticazione .
GET/qcbin/Autenticazione-point/autenticazione Autorizzazione: Base abcde123
Server convalida le intestazioni di autenticazione di base, crea una nuova LW-SSO token e restituisce come LWSSO_COOKIE_KEY.