I am trying to enter a site on a company intranet that has a basic dialog box pop-up authentication and forms-based authentication. This is the code I'm using (which leads to 401 => Net :: HTTPUnauthorized error):
require 'rubygems' require 'mechanize' require 'logger' agent = WWW::Mechanize.new { |a| a.log = Logger.new("mech.log") } agent.user_agent_alias = 'Windows Mozilla' agent.basic_auth('username','password') agent.get('http://example.com') do |page| puts page.title end
As a result, error 401 => Net :: HTTPU is raised. The following is mech.log information:
I, [2011-03-13T17:25:21.900631 #22128] INFO -- : Net::HTTP::Get: /index.asp?LogIn=yes&action=7 D, [2011-03-13T17:25:21.901631 #22128] DEBUG -- : request-header: accept-language => en-us,en;q=0.5 D, [2011-03-13T17:25:21.901631 #22128] DEBUG -- : request-header: accept => *
At this moment I am trying to pass the first basic authentication. I noticed one thing: the IIS server and the Mechanize documentation there is a public function gen_auth_headers (), however in the code from gem I use this function does not exist, plus what it does in the code is outside of me.
TIA, NABS
authentication ruby ruby-on-rails mechanize
Nabs
source share