I have a method that gets the html off a page. I give it a word to
look up, and it returns the results. I just switched to read from a
password-protected page, and I can’t figure out how to send along the
password so I can get authorized to read the page. Anyone know how to
do this?
I have a method that gets the html off a page. I give it a word to
look up, and it returns the results. I just switched to read from a
password-protected page, and I can’t figure out how to send along the
password so I can get authorized to read the page. Anyone know how to
do this?
def getWordResults(word)
require ‘open-uri’
begin @page = open(“http://joe.com/find?word=#{word}&lb=1&user=joe”).read
rescue # if page won’t open
nil
end
end
If it helps at all, I can get to the page using a browser and manually
entering the user and password. Does anyone know how to do that
automatically?
You might have to make the first arg to .set_auth be just the URL
without the query string.
Also, if the service doesn’t send back an authorization request (which
it sounds like it does since the browser asks you), then HTTPClient
won’t volunteer the credentials you’ve provided.