Hello, 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joe Peck wrote:> Hello, > > 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 > endIf 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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If it is using http authentication, you can use the format of http://user:password-44+HZZGY6NA@public.gmane.org?restofurl --- Chris On Nov 14, 2007 12:22 PM, Joe Peck <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Joe Peck wrote: > > Hello, > > > > 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? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 14, 2007, at 12:45 PM, Chris Evans wrote:> If it is using http authentication, you can use the format of > http://user:password-44+HZZGY6NA@public.gmane.org?restofurl > > --- > Chris > > On Nov 14, 2007 12:22 PM, Joe Peck <rails-mailing-list@andreas- > s.net> wrote: >> >> Joe Peck wrote: >>> Hello, >>> >>> 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 can use httpclient for this kind of thing: require ''rubygems'' require ''httpclient'' url = "http://joe.com/find?word=#{word}&lb=1&user=joe" client = HTTPClient.new client.debug_dev = STDOUT if $DEBUG client.set_auth(url, ''joe'', ''thePassw0rd'') resp = client.get(url) @page = resp.content 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. You can check things like if resp.status != 200 -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---