Próbuję wysłać żądanie do usługi REST(HP ALM 11 REST API fwiw) używającego klienta-klienta i wciąż otrzymuje nieautoryzowaną odpowiedź. Możliwe, że nie podążam za dokumentami, ale także nie jestem pewien, czy poprawnie wykonuję nagłówki. Do tej pory moje szukanie w Google dla RestClient było bezowocne. Każda pomoc będzie doceniona:
Kod:
@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
Oparte na tym WIĘC pytanie Próbowałem również następujące bez powodzenia:
@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
Dokumentacja:
Klient wysyła do uwierzytelnienia prawidłowy nagłówek podstawowego uwierzytelnienia punkt.
GET / qcbin / authentication-point / authenticate Autoryzacja: podstawowa ABCDE123
Serwer sprawdza poprawność podstawowych nagłówków uwierzytelniania, tworzy nowe Token LW-SSO i zwraca go jako LWSSO_COOKIE_KEY.
Odpowiedzi:
7 dla odpowiedzi № 1Okej ... więc najpierw pomaga, gdy przejdę do właściwego adresu URL:
authentication_url = @alm_url + "rest/is-authenticate"
Który powinien przeczytać:
authentication_url = @alm_url + "authentication-point/authenticate"
Po drugie, pomaga, jeśli czytam dokumenty dla RestClient, a nie tylko patrzę na readme. Przykład poniżej Szczegóły metody wystąpienia bardzo pomogło.
Mój kod wygląda teraz tak:
@alm_url = "http://alm_url/qcbin/"
@user_name = "username"
@user_password = "password"
authentication_url = @alm_url + "authentication-point/authenticate"
resource = RestClient::Resource.new(authentication_url, @user_name, @user_password)
response = resource.get
Rails.logger.debug response.inspect
EDYTOWAĆ:
Wow, naprawdę nad tym myślałem. Mogłem pójść z:
response = RestClient.get "http://#{@user_name}:#{@user_password}@alm_url/qcbin/authentication-point/authenticate"