title: How do I do Rails Basic Authorization with RestClient?
body: <p>I am trying to post a request to a REST service (HP ALM 11 REST API fwiw) using rest-client and keep getting the Unauthorized response. Could be I am not following the docs right but also I am not sure I am doing the headers properly. So far my googling for RestClient has been fruitless. Any help would be appreciated:</p>
  
  <p>Code:</p>
  
  <pre><code>@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 =&gt; Base64.encode64(@user_name) + ":" + Base64.encode64(@user_password)
  response = resource.get
  
  
  #response = RestClient.get authentication_url, :authorization =&gt; @username, @user_password
  Rails.logger.debug response.inspect
  </code></pre>
  
  <p>Based on this <a href="https://stackoverflow.com/questions/3692574/basic-auth-with-rest-client">SO question</a> I also tried the following without success:</p>
  
  <pre><code>@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 =&gt; @user_name, :password =&gt; @user_password}
  response = resource.get
  
  
  #response = RestClient.get authentication_url, :authorization =&gt; @username, @user_password
  Rails.logger.debug response.inspect
  </code></pre>
  
  <p>Documentation:</p>
  
  <blockquote>
    <p>Client sends a valid Basic Authentication header to the authentication
    point.</p>
    
    <p>GET /qcbin/authentication-point/authenticate  Authorization: Basic
    ABCDE123 </p>
    
    <p>Server validates the Basic authentication headers, creates a new
    LW-SSO token and returns it as LWSSO_COOKIE_KEY.</p>
  </blockquote>