HTTPS Proxy and LWP::UserAgent

后端 未结 8 2136
说谎
说谎 2020-12-17 02:18

I have read a number of threads on a number of sites and am still unable to make this work.

I have a client machine (OSX) with OpenSSL 0.9.8r running perl 5.12.4, w

8条回答
  •  情书的邮戳
    2020-12-17 02:47

    Why would you want "Force use of Net::SSL". Try

    #!/usr/bin/perl    
    use strict;
    use warnings;
    use LWP::UserAgent;
    
    BEGIN {
      $ENV{HTTPS_PROXY} = 'https://192.168.1.11:80';
    #  $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
      $ENV{HTTPS_DEBUG} = 1;  #Add debug output
    }
    
    my $ua = LWP::UserAgent->new();
    my $req = HTTP::Request->new('GET','https://github.com/');
    my $response = $ua->request($req);
    print $response->code ."\n";
    

    An out put of 200 should mean that there were no errors.

    A below sample code of mine works perfectly

    #!/usr/bin/perl
    use warnings;
    use LWP::UserAgent;
    
    BEGIN {
      $ENV{HTTPS_PROXY} = 'https://176.9.209.113:8080'; #Valid HTTPS proxy taken from http://hidemyass.com/proxy-list/
      $ENV{HTTPS_DEBUG} = 1;
    }
    
    my $ua = new LWP::UserAgent;
    my $req = new HTTP::Request('GET', 'https://www.nodeworks.com');
    my $res = $ua->request($req);
    print $res->code, "\n";
    

    Output-

    200
    SSL_connect:before/connect initialization
    SSL_connect:SSLv2/v3 write client hello A
    SSL_connect:SSLv3 read server hello A
    SSL_connect:SSLv3 read server certificate A
    SSL_connect:SSLv3 read server key exchange A
    SSL_connect:SSLv3 read server done A
    SSL_connect:SSLv3 write client key exchange A
    SSL_connect:SSLv3 write change cipher spec A
    SSL_connect:SSLv3 write finished A
    SSL_connect:SSLv3 flush data
    SSL_connect:SSLv3 read finished A
    SSL_connect:before/connect initialization
    SSL_connect:SSLv2/v3 write client hello A
    SSL_connect:SSLv3 read server hello A
    SSL_connect:SSLv3 read server certificate A
    SSL_connect:SSLv3 read server key exchange A
    SSL_connect:SSLv3 read server done A
    SSL_connect:SSLv3 write client key exchange A
    SSL_connect:SSLv3 write change cipher spec A
    SSL_connect:SSLv3 write finished A
    SSL_connect:SSLv3 flush data
    SSL_connect:SSLv3 read finished A
    
    Tool completed successfully
    

    With https://github.com/ the output is-

    200
    SSL_connect:before/connect initialization
    SSL_connect:SSLv2/v3 write client hello A
    SSL_connect:SSLv3 read server hello A
    SSL_connect:SSLv3 read server certificate A
    SSL_connect:SSLv3 read server done A
    SSL_connect:SSLv3 write client key exchange A
    SSL_connect:SSLv3 write change cipher spec A
    SSL_connect:SSLv3 write finished A
    SSL_connect:SSLv3 flush data
    SSL_connect:SSLv3 read finished A
    
    Tool completed successfully
    

    So having said all this. Your code version (below) should work fine-

    use warnings;
    use LWP::UserAgent;
    
    BEGIN {
      $ENV{HTTPS_PROXY} = 'https://176.9.209.113:8080';
      $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; #works even with this
      $ENV{HTTPS_DEBUG} = 1;  #Add debug output
    }
    
    my $ua = new LWP::UserAgent;
    my $req = new HTTP::Request('GET', 'https://github.com/');
    my $res = $ua->request($req);
    print $res->code, "\n";
    
    if ($res->is_success) {
         print $res->decoded_content;  # or whatever
         exit(0);
    }
    else {
     print "\nFail:\n";
         print $res->status_line ."\n";
         exit(1);
    }
    

提交回复
热议问题