我尝试使用LWP :: UserAgent设置凭据,但我无法登录。$username
,$passwd
是正确的。我不明白我应该在3rd argument
中添加什么(根据dos $realm
,Authentication
)。这里是片段:
my $browser = LWP::UserAgent->new(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/31.2.0',
$browser->credentials("domain.com:80", "Authentication",$username, $passwd);
my $response=$browser->get("http://domain.com/page");
print $response->content;
答案 0 :(得分:4)
我更正了领域@ThisSuitIsBlackNot建议:
Close your browser and reopen it. Navigate to http://domain.com/page.
If the site is using basic authentication,
you should get a popup that says something like
A username and password are being requested by
http://domain.com. The site says: "foo bar".
In this case, foo bar is the realm.
然后我能够登录,但页面都是空的。 所以我添加了一个cookie:
$browser->cookie_jar({ file => ".mycookies.txt" });