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

first off, this is my first post, i scanned through the faq did some searches, and now am here.

anyway, i'm trying to access this server with http requests and it's something i've never done before.

the curl looks like this:

curl https://secondroad.harvestapp.com/account/who_am_i -H 'Accept: application/xml' -H 'Content-Type: application/xml' -u elliott.williams@secondroad.com.au:******

and i get out this:

<?xml version="1.0" encoding="UTF-8"?> <hash> <user> <timezone>Sydney</timezone> <admin type="boolean">true</admin> <timestamp-timers type="boolean">false</timestamp-timers> <email>elliott.williams@secondroad.com.au</email> <id type="integer">111331</id> </user> </hash>
and that's perfect. i just can't figure out how to do it with a perl script. i'd like to do it without using any modules but LWP seems to be working.

thanks for the help. if i'm a complete idiot and there is a guide online for this, please direct me there, i've been messing around with this:

http://www.perl.com/pub/a/2002/08/20/perlandlwp.html?page=4

for a day with no luck.

cheers

Replies are listed 'Best First'.
Re: https request i got the cURL working
by Anonymous Monk on Mar 17, 2010 at 03:34 UTC
    See qx in perlop
    my $xml = qx{curl https://secondroad.harvestapp.com/account/who_am_i - +H 'Accept: application/xml' -H 'Content-Type: application/xml' -u ell +iott.williams@secondroad.com.au:******}
    Alternatively use IPC::System::Simple
      this is what i get when i type in the curl into the command line:

      [dodgers]$ curl https://secondroad.harvestapp.com/account/who_am_i -H +'Accept: application/xml' -H 'Content-Type: application/xml' -u ellio +tt.williams@secondroad.com.au:***** <?xml version="1.0" encoding="UTF-8"?> <hash> <user> <admin type="boolean">true</admin> <timestamp-timers type="boolean">false</timestamp-timers> <email>elliott.williams@secondroad.com.au</email> <id type="integer">111331</id> <timezone>Sydney</timezone> </user> </hash>

      and this is what i get when i use the previously mentioned perl code:

      [dodgers]$ perl perl_requests.pl % Total % Received % Xferd Average Speed Time Time Time + Current Dload Upload Total Spent Left + Speed 0 38 0 38 0 0 214 0 --:--:-- --:--:-- --:--: +-- 0 Authentication failed for API request.[dodgers]$

      the code for the perl program is:

      #!/usr/bin/perl my $xml = qx{curl https://secondroad.harvestapp.com/account/who_am_i - +H 'Accept: application/xml' -H 'Content-Type: application/xml' -u ell +iott.williams@secondroad.com.au:*****}; print $xml;
        Um, try this
        my @stuff = qw'curl ....'; print "@stuff"; print qx!@stuff!;