I'm trying to access a REST interface from the Kentico CMS and I don't seem to be able to access it properly in my Rails application. I can access it in the browser, and I get a username/password authentication box that pops up, which then gives me the JSON back after entering the proper credentials.
In my Rails application, I am using rest-client and trying to access via the following:
username = 'username_here'
password = 'password_here'
page_url = 'page_url_here'
resource = RestClient::Resource.new(page_url, :username => username, :password => password)
response = resource.get
Also tried:
resource = RestClient::Resource.new(page_url)
resource.head :Authorization => Base64.encode64(username) + ":" + Base64.encode64(password)
response = resource.get
Both give me an error of connection refused. Kentico's documentation says each request needs to be sent with an authorization header like so:
Authorization: Basic <enter Base64-encoded <username>:<password> here>
So I assume I must not be sending the headers correctly, or possibly the rest-client gem is just not up to the task. I am open to using other gems or entirely different approaches. Any help is appreciated!
Edit:
I was able to get rid of the connection refused error by changing the second example to the following:
resource = RestClient::Resource.new(page_url)
resource.head :Authorization => "Basic " + Base64.encode64("%s:%s" % [username, password])
However, I am now getting a 405 Method Not Allowed error. Is there something else in the header the browser is sending that rest-client is not?