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

Hi there Monks,

I need to access a database through a HTTP interface. It all start with getting a login token to get going. Using a webbrowser or curl on the command line I can do this quite effortless

On a curl request:

curl 'https://somesite:8800/?library=Algemeen&function=Login&UserName= +SomeUser&Password=SomePass'
I get back a piece of HTML:
<table><tr><td><b>Result</b></td><td ID="Result">True</td><tr><tr><td> +<b>ResultMessage</b></td><td ID="ResultMessage"></td><tr><tr><td><b>S +essionToken</b></td><td ID="SessionToken">sometoken</td><tr></table>

just as I expected. So I went ahead and made a small script with LWP doing the same thing:

#! /usr/bin/perl -w use strict; use HTTP::Request; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $url = 'https://somesite:8800/'; my $req = HTTP::Request->new(POST => $url); $req->content_type('application/x-www-form-urlencoded'); $req->content('library=Algemeen&function=Login&UserName=SomeUser&Passw +ord=SomePass'); my $res = $ua->request($req); if ($res->is_success){ print $res->content; }else{ print $res->status_line, "\n"; }
But alas... this returns a webpage instead of the table structure like it did with curl.

What is the difference between the curl example and the LWP example? Im kinda at a loss with this

Peter

Replies are listed 'Best First'.
Re: LWP and Curl results differ
by choroba (Cardinal) on Sep 10, 2018 at 09:39 UTC
    The main difference is you're using GET with curl, but POST with LWP.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      You're absolutely right... thanks :D