Temel kimlik doğrulaması açılır iletişim kutusu ve form tabanlı kimlik doğrulaması olan şirket intranetinde bir siteye giriş yapmaya çalışıyorum.Temel ve Form Kimlik Doğrulaması (Ruby)
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
Bu 401 => Net :: HTTPUnauthorized hatası ile sonuçlanır: Bu (401 => Net :: HTTPUnauthorized hata ile sonuçlanır) kullanıyorum kodudur.
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 => */*
D, [2011-03-13T17:25:21.901631 #22128] DEBUG -- : request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6
D, [2011-03-13T17:25:21.902631 #22128] DEBUG -- : request-header: connection => keep-alive
D, [2011-03-13T17:25:21.902631 #22128] DEBUG -- : request-header: accept-encoding => gzip,identity
D, [2011-03-13T17:25:21.902631 #22128] DEBUG -- : request-header: host => example.com
D, [2011-03-13T17:25:21.902631 #22128] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
D, [2011-03-13T17:25:21.903631 #22128] DEBUG -- : request-header: keep-alive => 300
D, [2011-03-13T17:25:22.813722 #22128] DEBUG -- : Read 24 bytes
D, [2011-03-13T17:25:22.814722 #22128] DEBUG -- : response-header: content-type => text/html
D, [2011-03-13T17:25:22.815722 #22128] DEBUG -- : response-header: connection => close
D, [2011-03-13T17:25:22.815722 #22128] DEBUG -- : response-header: www-authenticate => Negotiate, NTLM, Basic realm="example.com"
D, [2011-03-13T17:25:22.816722 #22128] DEBUG -- : response-header: date => Sun, 13 Mar 2011 11:55:21 GMT
D, [2011-03-13T17:25:22.817722 #22128] DEBUG -- : response-header: server => Microsoft-IIS/5.0
D, [2011-03-13T17:25:22.817722 #22128] DEBUG -- : response-header: content-length => 24
I, [2011-03-13T17:25:22.819723 #22128] INFO -- : status: 401
Ben sadece ilk temel kimlik doğrulaması geçmiş olsun çalışıyorum Bu noktada Aşağıda mech.log bilgilerdir. Sunucu IIS ve Mechanize documentation içinde gen_auth_headers() adında bir genel işlev olduğunu, ancak bu işlevin kullanılmadığı taş kodunda ancak varolduğunu fark ettim. Kod benim dışımda.
TIA,
Doğru, üzgünüm bu satırı eklemeyi unuttum. Aslında, ben – Nabs
için bir takma ad olan basic_auth kullandım, yukarıda Mechanize 1.0.0 ile test ettim ve işe yarıyor. Kullanmakta olduğunuz sürümde bir hata olabilir. –
Agent.auth'un artık kullanımdan kaldırıldığına inanıyorum. Bunun yerine agent.add_auth (bölge, kullanıcı adı, parola) –