为什么我的LWP :: UserAgent凭据不起作用? [英] Why don't my LWP::UserAgent credentials work?
问题描述
我正在尝试访问受保护的文件.服务器正在使用摘要身份验证-从打印出来的响应中可以看到. 这是示例代码:
I'm trying to access a protected file. Server is using digest authentication - which I can see from the printed out response. Here is the sample code:
use LWP;
use strict;
my $url = 'http://somesite.com/aa/bb/cc.html';
my $username = 'scott';
my $password = 'tiger';
my $browser = LWP::UserAgent->new('Mozilla');
$browser->credentials("http://somesite.com:80","realm-name",$username=>$password);
my $response=$browser->get($url);
print $response->content;
我从浏览器访问该资源时从弹出窗口中获得的领域名称.相同的用户名和密码在浏览器中可以正常工作,并且可以看到内容,但是在运行上述脚本时,它始终显示401 Authorization required
.
Name of the realm I got it from the popup window I get when I try to access that resource from the browser. Same username and password are working extremely fine in the browser and I'm able to see the content but when I run the above script it always says 401 Authorization required
.
LWP如何工作?
我是否需要让LWP发送用户名和密码的MD5哈希值(摘要),还是在内部像它在检查要使用的身份验证并发送相应的(基本/摘要)发送凭据的方式? 我的问题是
Do I need to ask LWP to send MD5 hash (digest) of the username and password or is it like internally it checks which authentication to use and sends the corresponding (basic/digest) way of sending credentials. My questions are
- 如何设置LWP,以便它发送用户名和密码的摘要?
- 如果服务器使用Windows NTLM身份验证协议怎么办?在这种情况下我该怎么办?
任何快速帮助都将受到高度赞赏!
any quick help is highly appreciated !
推荐答案
请考虑以下LWP::UserAgent
模块文档中的摘录:
Consider the following excerpt from the LWP::UserAgent
module's documentation:
$ua->credentials( $netloc, $realm )
$ua->credentials( $netloc, $realm, $uname, $pass )
$ua->credentials( $netloc, $realm )
$ua->credentials( $netloc, $realm, $uname, $pass )
获取/设置要用于领域的用户名和密码.
Get/set the user name and password to be used for a realm.
$netloc
是格式为"<host>:<port>"
的字符串.用户名和密码将仅传递到此服务器.示例:
The $netloc
is a string of the form "<host>:<port>"
. The username and password will only be passed to this server. Example:
$ua->credentials("www.example.com:80", "Some Realm", "foo", "secret");
更改
$browser->credentials("http://somesite.com:80","realm-name",$username=>$password);
到
$browser->credentials("somesite.com:80","realm-name",$username=>$password);
这篇关于为什么我的LWP :: UserAgent凭据不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!