Automatic HTTP Basic Authentication In Ruby on Rails

Well, you may want to use HTTP basic auth mechanism of Net::HTTP library.
Basically this is how i would do it:

require 'net/http'

req =
req.body = xml_query # contents the raw query
req.content_type = "application/x-www-form-urlencoded"
req.content_length = xml_query.length

    result = nil
      timeout(3) do
        _result =,url.port).start { |http|
        result = _result.body
    rescue Timeout::Error
      result = nil
      result = nil

But probably you want a much simpler solution, another solution would
be to use SimpleHttp library.

str = SimpleHttp.get URI.parse("")