Parsing json which require username and password

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?serviceprops=42&servicestatustypes=28&type=detail&hostprops=10&host=all&page=1&entries=all&view_mode=json”)

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

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 Sat, Dec 8, 2012 at 9:47 AM, Ferdous ara [email protected]
wrote:

current=`curl -fs -basic -u “username:password”

http://ourmonitoringsystem.lan/cgi-bin/status.cgi?serviceprops=42&servicestatustypes=28&type=detail&hostprops=10&host=all&page=1&entries=all&view_mode=json`

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

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 Sat, Dec 8, 2012 at 11:33 AM, Ferdous ara [email protected]
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