0

I can connect to a remote url using the proxy from tsocks in the following way:

tsocks telnet host port

How can I do the same using the Perl's LWP::UserAgent module? I've been so far trying it like this, but it doesn't work:

use strict;
use warnings;
use v5.16;
use LWP::UserAgent;
use HTTP::Request::Common;
use Data::Dumper;

#my $ua = LWP::UserAgent->new();
my $ua  = LWP::UserAgent->new(timeout => 10,
    ssl_opts => {
        #verify_hostname => 0,
        verify_hostname => 0,
        SSL_verify_mode => '0x01',
        SSL_version     => 'SSLv23:!SSLv3:!SSLv2',
    }
);
$ua->proxy(['http', 'https' ], 'https://proxy_host:proxy_port' );

my $request = GET ( 'https://remote_url', Accept => 'application/json' );
$request->authorization_basic( 'username', 'password' );
say $request->as_string();

my $response = $ua->request( $request );
say $response->as_string();

By the way, I don't have socks installed on this server. So I'll need to do it without them.

Thanks!

mirchev1977
  • 167
  • 12

2 Answers2

1

LWP::UserAgent and SOCKS

You may use LWP::Protocol::socks perl package make LWP::UserAgent SOCKS capable.

IMHO it is much better way for your own perl scripts.
tsocks may be better for legacy perl scripts you do not want to modify.

AnFi
  • 10,493
  • 3
  • 23
  • 47
0

I found a solution which might be very specific for my case:

Before running the script, I just call tsocks like this:

tsocks script_name.pl
mirchev1977
  • 167
  • 12