Hi
I want Fetch a web page which has json output, but the problem is, that
page has username and password, so i am using like this
require "rubygems"
require "json"
require "net/http"
require "uri"
uri =
URI.parse("http://ourmonitoring/cgi-bin/status.cgi?servicepro...)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
if response.code == "200"
result = JSON.parse(response.body)
puts result
"
end
else
puts "ERROR!!!"
end
puts result
But problem is, dont know how to pass Username and password,
Can any one please give me some light please
Fosiul
on 2012-12-08 09:47
on 2012-12-08 10:01
All GET requests pass data as name/value pairs in the query string, which is everything after the ? in the url. However, you have to know what name the cgi script is expecting for the user and password. For instance, should you write: ...?user=NAME&passw=SOMETHING... Or: ...?username=NAME&password=SOMETHING... Or, something else. You know the values, but you have to know the names too.
on 2012-12-08 10:59
On Sat, Dec 8, 2012 at 9:47 AM, Ferdous ara <lists@ruby-forum.com> wrote: > current=`curl -fs -basic -u "username:password" > http://ourmonitoringsystem.lan/cgi-bin/status.cgi?... > > result=JSON.parse(current) > > puts result > > > But ts its giving me data + html output .. > > what will be the best way to achive my goal ? If the request returns HTML you need a HTML parser and not a JSON parser. -> Nokogiri Cheers robert
on 2012-12-08 11:33
HI thanks but i found the solution i had to use , because its using the Basica Auth mode in apache, the bellow command fix the issue request.basic_auth 'xxx','xxx'
on 2012-12-09 13:44
On Sat, Dec 8, 2012 at 11:33 AM, Ferdous ara <lists@ruby-forum.com> wrote: > HI thanks > but i found the solution > > i had to use , because its using the Basica Auth mode in apache, the > bellow command fix the issue > > > request.basic_auth 'xxx','xxx' i'd also look into mechanize gem if you do need to to more interactions with the weg page. Kind regards robert
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.