+ -
当前位置:首页 → 问答吧 → LWP::UserAgent 登陆HTTPS不成功

LWP::UserAgent 登陆HTTPS不成功

时间:2010-11-24

来源:互联网

如题,我用以前一个老大帮忙写的Perl脚本来登陆https 一直登陆失败,这是post的数据
下载 (4.48 KB)
2010-11-24 09:38

https://www.test.com/passport/?pid=UserCenter    这是登陆框URL

  1. #!/use/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use Data::Dumper;
  5. use HTTP::Cookies;
  6. use LWP::UserAgent;
  7. my $local_dir = '/data';
  8. my $login_url = 'https://www.test.com/Passport/LogOnSubmit?';
  9. my %login_form = (
  10.         'username' => 'admin,
  11.         'password' => '111111',
  12.         'UserCenter'=>'UserCenter',
  13.         'validateCode'=>'jbjk',
  14.         'loginType'=> '0',

  15. );
  16. my $ie = LWP::UserAgent->new();
  17. # 获得COOKIE
  18. my $response = $ie->get( $login_url );
  19. my $cookie;
  20. if ( $response->is_success ) {
  21.         my $cookie_jar = HTTP::Cookies->new;
  22.         $cookie_jar->extract_cookies($response);
  23.         my $cookie_temp = $cookie_jar->as_string();
  24.         ($cookie) = ($cookie_temp =~ /.*?(ASP.NET_SessionId=.*?)\;.*?/i);
  25.         #($cookie) = ($cookie_temp =~ /.*?(PHPSESSID=.*?)\;.*/i);
  26. }
  27. # 登录
  28. $ie->default_header('Cookie'=>$cookie,'Referer'=>$login_url);
  29. $response = $ie->post( $login_url, \%login_form);
  30. print Dumper($response->as_string);
  31. #my %hash;
  32. #foreach ( split(/\n/,$response->as_string) ) {
  33. #        my ($key,$value) = split(/: /,$_);
  34. #         $hash{$key} = $value;
  35. #}
  36. #if ( $hash{'Location'} ) {
  37.         #print "login successful!\n";
  38. #}
  39. #else {
  40.         #print "login error!\n";
  41. #}
  42. # 登录成功后页面请求
  43. #$response = $ie->get('https://www.test.com/Passport/Tenants');
  44. #$response = $ie->get($hash{'Location'});
  45. #print $response;
  46. #open(FH,">wewele.html");
  47. #print FH $response->content;
  48. #close FH;
  49. #<>;
复制代码

作者: mitmax   发布时间: 2010-11-24

本帖最后由 黑色阳光_cu 于 2010-11-24 10:06 编辑

没装CA?

http://stackoverflow.com/questio ... server-certificates

作者: 黑色阳光_cu   发布时间: 2010-11-24

还是curl好用

http://search.cpan.org/dist/WWW-Curl/lib/WWW/Curl.pm

作者: 黑色阳光_cu   发布时间: 2010-11-24