On 3/26/07, Kiran
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> Hi,
>
> i need to access a url
> www.sometesturl3456.com/index.php
>
> It prompts HTTP Authentication window asking username and password. I
> have do automatic HTTP Basic authentication without manual entry of
> username and password, as i am reading the content of page in ruby in
> rails using:
>
> response = open("www.sometesturl3456.com/index.php").read
>
> Please help me to know how this can be done.
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 = Net::HTTP::Post.new(url.path)
req.basic_auth("username","password")
req.body = xml_query # contents the raw query
req.content_type = "application/x-www-form-urlencoded"
req.content_length = xml_query.length
result = nil
begin
timeout(3) do
_result = Net::HTTP.new(url.host,url.port).start { |http|
http.request(req)}
result = _result.body
end
rescue Timeout::Error
result = nil
rescue
result = nil
end
But probably you want a much simpler solution, another solution would
be to use SimpleHttp library.
str = SimpleHttp.get
URI.parse("http://username:password-NCzvY20eV+mnzT0iUeSTvQ@public.gmane.org")
URL:
http://simplehttp.rubyforge.org/
--
gnufied
-----------
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---