2

我的以下代码适用于其他 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); 
4

1 回答 1

2

IO::Socket::SSL 默认使用 SSLv2,并且该服务器不会重新协商以升级到 v3。因此,立即与 v3 连接,并且可以正常工作。

LWP::UserAgent->new(ssl_opts => {SSL_version => 'SSLv3'})
于 2013-09-04T17:37:47.713 回答