3

我试图让 LWP 与配置了 NTLM 身份验证的 IIS 服务器一起工作。当服务器上的 NTLM 身份验证关闭时,代码工作正常,所以我认为这里唯一的问题是 NTLM 身份验证。

到目前为止,我有以下内容:

my $ua = LWP::UserAgent->new(agent => "whatever",
                            timeout => $timeout, keep_alive => 1);
$ua->credentials('hostname:80', '', $username, $password);

my $hdr = HTTP::Headers->new("Content-Type" => "text/xml; charset=UTF-8",
                             "SOAPAction" => "\"whatever\"");

my $req = HTTP::Request->new("POST" => $url, $hdr, encode_utf8($post));
$res = $ua->request($req);

如果我打开调试,我会收到以下消息:

LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: POST http://hostname
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::http::request: Keep the http connection to hostname:80
LWP::UserAgent::request: Simple response: Unauthorized
LWP::Authen::Ntlm::authenticate: authenticate() has been called
Use of uninitialized value in exists at /usr/lib/perl5/vendor_perl/5.8.5/LWP/UserAgent.pm line 560.
Use of uninitialized value in hash element at /usr/lib/perl5/vendor_perl/5.8.5/LWP/UserAgent.pm line 561.
LWP::Authen::Ntlm::authenticate: In first phase of NTLM authentication
[Thu Apr 12 13:55:28 2012] [error] Wide character in subroutine entry at /usr/lib/perl5/site_perl/5.8.5/Authen/NTLM.pm line 346.\n
LWP::Protocol::collect: read 625 bytes
LWP::UserAgent::request: Simple response: Internal Server Error

尝试访问相同的 URL 可以wget正常工作。的文档MIME::Base64说,Wide character in subroutine entry如果 $bytes 包含代码高于 255 的字符,则编码函数将发出嘶嘶声。

我是否在这里遗漏了一些重要的东西,或者这可能是一个错误Authen::NTLM

4

2 回答 2

-1

$post 中有什么?也许是包含错误数据。

尝试这个:

my $post_encoded = encode_utf8($post);
print Dumper($post,$post_encoded);
my $req = HTTP::Request->new("POST" => $url, $hdr, $post_encoded);
于 2012-04-12T12:24:56.930 回答
-4

只需使用卷曲

curl --ntlm -u 'username:password' url 
于 2012-04-12T18:18:44.307 回答