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

Hi,

I am trying to write a code in perl to send the following http instruction to a satellite receiver (i checked the expression in my browser and it works well) but I don't master perl well enough to send this instruction.

http://10.0.1.2:8080/frql?cmd=set_alarm&sat_idx=89&svc_type=0&svc_idx=4&alarm_id=4&alarm_type=1&alarm_mode=1&alarm_days=0&stime=%222016-2-9T22:25%22&etime=%222016-2-10T1:0%22&evt_id=61

The following expressions within the url string are variables and I will need to make them equal specific values that will be entered as argument when the perl code is launched

sat_idx

svc_idx

stime

etime

Can anyone help?

Replies are listed 'Best First'.
Re: sending http request
by haukex (Archbishop) on Sep 25, 2016 at 17:16 UTC

    Hi rogerdsw6,

    If it's just a simple GET request, you could use HTTP::Tiny to send the request, which has been a core module for a few years now.

    To build the request URL, I'd recommend the module URI, for which I once wrote some simple example code here.

    Hope this helps,
    -- Hauke D

Re: sending http request
by Your Mother (Archbishop) on Sep 25, 2016 at 17:41 UTC

    :P

    #!/usr/bin/env perl use strictures; use URI; use Data::Dumper; use WWW::Mechanize; @ARGV == 4 or die "Give satellite id, service id, stime, and etime!\n" +; my ( $sat, $svc, $stime, $etime ) = @ARGV; my $uri = URI->new("http://10.0.1.2:8080/frql"); my %args = ( alarm_days => 0, alarm_id => 4, alarm_mode => 1, alarm_type => 1, cmd => "set_alarm", svc_type => 0, sat_idx => $sat, svc_idx => $svc, stime => $stime, etime => $etime ); $uri->query_form( %args ); print $uri, $/; print Dumper({ $uri->query_form }); my $mech = WWW::Mechanize->new; $mech->get($uri); print $mech->response->as_string, $/;

    Adjust, amend as necessary.

Re: sending http request
by ww (Archbishop) on Sep 25, 2016 at 17:24 UTC

    These may help you get help:

    1. On asking for help
    2. How do I post a question effectively?
    3. Getting Started with PerlMonks

    What have you tried?

    Please show us that you have actually tried to solve your question: (we expect SOPW to show effort seek wisdom; not to simply ask us to solve their problems for them) by posting code; verbatim warnings and error messages; and a narrative explanation of how your attempt falls short of your wishes.


    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.