当我尝试访问需要证书和身份验证的安全URL时使用perl,我收到“401 Unauthenticated error”。请帮忙。
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
# Create a request
my $req = HTTP::Request->new(GET => 'https://abc.xyz.com');
$req->content_type('application/x-www-form-urlencoded');
#$req->content('query=libwww-perl&mode=dist');
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
}
else {
print $res->status_line, "\n";
}
我尝试在google中搜索解决方案并在下面试过,但我仍然无法获得200状态。
use LWP::UserAgent;
$ua = new LWP::UserAgent;
my $req = HTTP::Headers->new;
$req = HTTP::Request->new(GET => 'https://abc.xyz.com:443');
$req->authorization_basic('USERNAME', 'PASSWORD');
print "Content-type: text/html\
\
";
my $response = $ua->request($req);
print $response->status_line;