我正在尝试让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
尝试使用wget
访问相同的网址正常。 MIME::Base64
的文档说如果$ bytes包含代码大于255的字符,则编码函数将与Wide character in subroutine entry
结合。
我在这里遗漏了一些必要的东西,或者这可能是Authen::NTLM
中的错误吗?
答案 0 :(得分:-1)
$ post中有什么内容?也许是包含不良数据。
试试这个:
my $post_encoded = encode_utf8($post);
print Dumper($post,$post_encoded);
my $req = HTTP::Request->new("POST" => $url, $hdr, $post_encoded);
答案 1 :(得分:-4)
只需使用curl
curl --ntlm -u 'username:password' url