我的以下代码适用于其他 https 网站,但不适用于 TopCoder。输出文件显示:Can't connect to community.topcoder.com:443 LWP::Protocol::https::Socket: SSL connect attempt failed with unknown error error:00000000:lib(0):func(0):reason(0) at C:/Perl64/lib/LWP/Protocol/http.pm line 51, line 2.
你能帮我知道哪里错了吗?非常感谢。
#!perl
use LWP::Simple;
use LWP::UserAgent;
use HTML::Form;
use HTTP::Cookies;
use Term::ReadKey;
use HTML::Parse;
print "Please enter your TopCoder username:";
chop(my $user=<stdin>);
print "Please enter your TopCoder password: (do not display)\n";
ReadMode 2;
chop(my $password=<stdin>);
ReadMode 0;
#log-in and set cookies
my $host="http://community.topcoder.com/tc?&module=MyHome";
my $method="GET";
my $cookie_jar=HTTP::Cookies->new;
require HTTP::Request;
my $ua=LWP::UserAgent->new;
$ua->cookie_jar({});
$ua->agent('Mozilla/5.0');
my $r=HTTP::Request->new;
my $response=HTTP::Response->new;
$r->method($method);
$r->uri($host);
$cookie_jar->add_cookie_header($r);
$response=$ua->request($r);
$cookie_jar->extract_cookies($response);
my $html;
my $baseuri;
if($response->is_success)
{
$html=$response->content;
$baseuri=$response->base;
}
else
{
$html = $response->error_as_HTML();
print "Server Connection Failed.\n";
exit 0;
}
my @forms=HTML::Form->parse($html,$baseuri);
my $form=$forms[1];
$form->value("username",$user);
$form->value("password",$password);
push @{ $ua->requests_redirectable }, 'POST';
$response=$ua->request($form->click);
if ($response->content =~/Username or password incorrect/i)
{
print "Wrong username or password!\n";
exit 1;
}
else
{
open(FO2, ">login_test.htm");
print FO2 $response->content;
$cookie_jar->extract_cookies($response);
print "Login OK\n";
}
$ua->cookie_jar($cookie_jar);