Leudwinus has asked for the wisdom of the Perl Monks concerning the following question:

Hello Fellow Monks,

I am trying to download the HTML of a URL which requires authentication (username and password). Using curl, I am able to successfully do this via:

curl --cookie "session=536...035a" -o "HTML_output.txt"

where the session ID is the one I obtained via the browser's developer tools function.

I am trying to replicate this using a more "native" Perl approach and using the LWP module, I have the following code which allows me to get the HTML of a given URL that does not require any authentication:

use LWP; my $url = ""; my $browser = LWP::UserAgent->new( ); my $resp = $browser->get($url); print $resp->content, "\n";

Is there a way using LWP (or some other module) to also include the session ID from the browser cookie?

Thank you in advance.

As a quick update, I have modified my code to use HTTP::Cookies::Netscape as follows:

use strict; use warnings; use LWP; use HTTP::Cookies::Netscape; my $url = ""; my $cookie_jar = HTTP::Cookies::Netscape->new( file => "/path/to/cookies.txt", ); my $browser = LWP::UserAgent->new( ); $browser->cookie_jar( $cookie_jar ); my $resp = $browser->get($url); print $resp->content, "\n";

Unfortunately, when I run that, the response that comes back tells me that I still need to supply a proper username and password, even though my session is still valid on the browser. I used the Firefox add-on "cookies.txt" to download a cookies.txt file which looks like:

# Netscape HTTP Cookie File TRUE / TRUE 1984932267 session 5361...1 +329