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

Bretheren, I have been given a bash shell script which uses wget to access a secure Web application for my company. I am trying to port the same thing into Perl so that I can do some serious parsing on the data and distribute the utility within my department. I have successfully installed LWP and openssl and have a script with connects to the login application. The response message shows that the login application is waiting for my data (so I know I have a valid secure socket). I have looked over the LWP and HTTP man pages and I cannot find how to implement the wget switches in LWP. Does anybody have a guide or an example of how the following switches should be implemented with an HTTP request message? --no-check-certificate --http-user --http-password --keep-session-cookies --post-data --user-agent I am using full-blown LWP (use LWP::UserAgent;). I would like to take the time to get this working completely in Perl instead of invoking wget since this needs to work across several systems. Thanks in advance for any insights.
  • Comment on Porting wget commandline switches to LWP

Replies are listed 'Best First'.
Re: Porting wget commandline switches to LWP
by Corion (Patriarch) on Dec 19, 2007 at 07:39 UTC

    To expand a bit on the reply by Anonymous Monk, you will need to find out what the wget command line switches do and then implement that in Perl.

    As a first start, I recommend WWW::Mechanize over using LWP::UserAgent directly, because WWW::Mechanize behaves more like a browser. The --http-user and --http-password switches sound to me like basic authentication, and I'm sure that LWP has something for basic authentication. --post-data will have to be supplied by you in a HTTP::Request::POST object, or, if you're using WWW::Mechanize, might simply come from a ->submit call. --user-agent is in WWW::Mechanize.

      WWW::Mechanize is a subclass of LWP::UserAgent - so can use all of its methods.

      You can do something like:
      my $agent = WWW::Mechanize->new(); $agent->credentials($uri->host_port, "TheRealm", "user", "pass");

      See LWP::UserAgent for details on credentials.

Re: Porting wget commandline switches to LWP
by Anonymous Monk on Dec 19, 2007 at 07:25 UTC