Mojo::useragent SSL failure

354 views Asked by At

i am using Mojo::Useragent to fetch some site behind a proxy which defined using HTTP_PROXY and HTTPS_PROXY

below an example of the code :

my $rs = $ua->insecure(1)->get($mysite) 
if($rs->res->is_success) {
    .....
} else {
    print "Problem with fetching $mysite \n";
    print $rs->res->error->{message};
}

I am getting this error:

SSL connect attempt failed error:14077419:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert access denied

While when i am using curl on the same machine I get the results as expected.

Any idea how to solve this issue?

1

There are 1 answers

0
GMB On BEST ANSWER

Form the SSL error, it looks like your network is actively refusing to let you through.

Defining environment variables HTTP_PROXY and HTTPS_PROXY is fine, however you need to tell Mojo::UserAgent to use them (unlike cURL, that automatically looks them up by default).

Add this line to your code before you run the query :

$ua->proxy->detect;

See the Mojo::UserAgent::Proxy documentation.

If you are looking for a pure Perl solution without using environment variables, you can configure the proxy manually, directly in your code, like :

$ua->proxy
      ->http('http://127.0.0.1:8080')
      ->https('http://127.0.0.1:8080');