perllwp-useragent

How to provide UA attributes for Image::Grab?


I try to add some UA attributes while using Image::Grab, like:

my $fp = 'sha256$26328...';
my $pic = Image::Grab->new( ua => { ssl_opts => { SSL_fingerprint => $fp } } );

I tried also as:

$pic->ua->ssl_opts( { SSL_fingerprint => $fp } ); 

Neither way UA (LWP) seems not get set properly. How to achieve the SSL_fingerprint setting? I need it because site's certificate has some chain flaw in and without specifying the fingerprint I can't connect it securely.


Solution

  • To set SSL options, you need to pass 2 arguments to the ssl_opts method of LWP::UserAgent: the name of the option and its value. Thus, you should do:

    $pic->ua->ssl_opts( SSL_fingerprint => $fp ); 
    

    In your code, you are passing a hash reference to ssl_opts ({ SSL_fingerprint => $fp }). When a single argument is passed to ssl_opts, this argument is expected to be the name of an option, and the function returns the value associated to this name.