perl - Perl 中的 NTLM 代理身份验证

标签 perl ntlm proxy-authentication

我需要通过代理访问互联网页面。 我需要使用 NTLM 或摘要身份验证方案

我在谷歌上搜索到的代码不起作用。

下面的代码使用任意 Auth header 发出 Web 请求。 请帮助我通过 NTLM 代理身份验证获取网页。

GET (URL address blocked: See forum rules) HTTP/1.1
TE: deflate,gzip;q=0.3
Keep-Alive: 300
Connection: Keep-Alive, TE
Host: google.com
User-Agent: libwww-perl/6.02


my $ua = new LWP::UserAgent(keep_alive => 1);
$ua->proxy('http', $PROXY);
$ua->credentials('proxy', '', 'username','passwd');
ntlmv2(1);

my $req = GET  $url;
print "--Peforming request now...---------\n";

my $res = $ua->request($req);
if ($res->is_success) {
    print $res->content;
} else {
    print "Error: " . $res->status_line . "\n";
    print $res->headers()->as_string(), "\n";
}

最佳答案

来自以下页面:http://www.perlmonks.org/?node_id=953031

use strict;
use warnings;
use Authen::NTLM;
use LWP::UserAgent;
use HTTP::Request::Common;

my $url = 'http://www.google.de';

my $ntlm = Authen::NTLM->new(
    host     => $url,
    user     => 'user',
    password => 'password',
);
my $reply = $ntlm->challenge;

my $ua = LWP::UserAgent->new(keep_alive => 1);
$ua->env_proxy;
$ua->protocols_allowed(['http']);

my $req = GET $url;
print "====Performing request now=========";

my $res = $ua->request($req);
if ($res->is_success) {
    print $res->content;
} else {
    print "Error: " . $res->status_line . "\n";
    print $res->headers()->as_string(), "\n";
}
print "====Done with request===============";
ntlm_reset;
exit;

关于perl - Perl 中的 NTLM 代理身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14930612/

相关文章:

python - 如何在字符串(python、perl)中找到表情符号、unicode 字符和表情符号的文本描述?

perl - 为什么 Perl 5 的函数原型(prototype)不好?

perl - 我如何 “untaint”一个变量?

python - 在 Windows 上使用 python 自动 NTLM

ios - 为什么我不能使 HttpWebRequest 与 NTLM 身份验证一起使用

arrays - 无法找到项目数组中是否存在一项并在 Perl 中返回必要的消息

java - WinRM(WsMan) 和 NTLM 身份验证

node.js - node.js 中的代理身份验证与模块请求

java - 重用授权 header 以防止 Jersey Client 的多个 407 代理身份验证挑战