in reply to Re^2: How to download or run exe file using rest client.
in thread How to download or run exe file using rest client.

Hello again Anonymous Monk,

I think I understand what you mean. I assume you are able to see the output of the page that you want to download but how to store it locally you mean.

There are many ways to do it, sample below:

#!/usr/bin/perl use strict; use warnings; use REST::Client; #The basic use case my $client = REST::Client->new(); $client->GET('https://perlmaven.com/'); print $client->responseContent(); __END__ $ perl test.pl > index.html

Further documentation for reference of alternative ways how do i redirect STDOUT, STDIN, or STDERR to a FILE? and https://perlmaven.com/simple-way-to-fetch-many-web-pages.

Let me know if still is not clear. BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^4: How to download or run exe file using rest client.
by Anonymous Monk on Mar 20, 2019 at 11:35 UTC
    Hi Thanos

    Thanks for the reply, below code is working for me to get the exe file but while executing that file, I am facing "filename header error".

    use strict; use LWP::Simple; my $url = "URL"; ##die "Couldn't get it!" unless defined $content; my $file = "BCM_console.exe"; my $code = getstore($url, "$file"); print "CODE : $code\n";
    Are there any headers I need to pass here, how we can pass them.
    Regards.

      If I run your code as it stands, but with a valid URL as the value for $url it succeeds fine. Therefore the problem is specific to the URL you are actually using. Since you haven't said what that is, it will be hard to help you further.

      #!/usr/bin/perl use strict; use LWP::Simple; my $url = "https://www.perlmonks.org/?node_id=1231486;part=1;abspart=1 +;displaytype=displaycode"; ##die "Couldn't get it!" unless defined $content; my $file = "BCM_console.exe"; my $code = getstore($url, "$file"); print "CODE : $code\n";

        HI hippo, Thanks for the reply.

        My url looks like below my $url = "http://server_address:port/ws/1/console/webstart?full=true" +; #Above url fetches the exe file as expected but I am not able to run i +t, getting "missing filename header error".

        Regards

      Hello again Anonymous Monk,

      It seems the file you are downloading in not executable. On this case it is not related to Perl but you need to get a valid file.

      I would also suggest a few minor configurations to your script to reduce the possibility of an error:

      #!/usr/bin/perl use strict; use warnings; use LWP::Simple; my $url = "URL"; my $file = "BCM_console.exe"; my $code = getstore($url, "$file"); die "Error: $code on $url" unless is_success($code);

      Hope this helps, BR.

      Seeking for Perl wisdom...on the process of learning...not there...yet!

      EXACT ERROR "missing filename header".

        What does running this show ?

        #!perl use strict; use warnings; use LWP::UserAgent(); printf "%s Perl %s LWP %s\n\n",$^O,$^V,$LWP::VERSION; my $url = 'URL'; my $ua = LWP::UserAgent->new; my $resp = $ua->head($url); print $resp->as_string;
        poj