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

I'm trying to Post to a web site using the following code:
#!/usr/bin/perl use HTTP::Request::Common qw(POST); use LWP::UserAgent; $ua = LWP::UserAgent->new; my $req = POST 'http://www.sfarmls.com/scripts/mgrqispi.dll', [ APPNAME => 'Sanfrancisco', PRGNAME => 'MLSLogin', ARGUMENTS => ('-ASS','-AA'), ]; print $ua->request($req)->as_string;

But when I do, I get an HTML file from www.sfarmls.com telling me that I'm using an invalid entry point.
However, I can easily access this site with the following telnet commands:
POST /scripts/mgrqispi.dll HTTP/1.1 Host: www.sfarmls.com Content-Length: 56 Content-Type: application/x-www-form-urlencoded APPNAME=Sanfrancisco&PRGNAME=MLSLogin&ARGUMENTS=-ASS,-AA

I'm a little confused why www.sfarmls.com is OK with the telnet access but not with the perl routine access.
Also, the perl routine directs the response to the terminal output. How can I direct the response to a variable within the perl program? Thanks, Matt

Replies are listed 'Best First'.
Re: posting with HTTP::Request::Common
by ikegami (Patriarch) on Nov 07, 2006 at 01:21 UTC
    [ APPNAME => 'Sanfrancisco', PRGNAME => 'MLSLogin', ARGUMENTS => ('-ASS','-AA'), ];

    is the same as

    [ APPNAME => 'Sanfrancisco', PRGNAME => 'MLSLogin', ARGUMENTS => '-ASS' -AA => undef, ];

    You were probably thinking of

    [ APPNAME => 'Sanfrancisco', PRGNAME => 'MLSLogin', ARGUMENTS => ['-ASS','-AA'], ];

    But that's not right either, since array refs are used to indicate the argument is a file to send.

    The docs doesn't give an example which has multiple arguments with the same name, but since an array is used I figure there's nothing special to it.

    [ APPNAME => 'Sanfrancisco', PRGNAME => 'MLSLogin', ARGUMENTS => '-ASS', ARGUMENTS => '-AA', ];

    Update: Oh wait, in your telnet example, there's only one ARGUMENTS fields with a single value.

    [ APPNAME => 'Sanfrancisco', PRGNAME => 'MLSLogin', ARGUMENTS => '-ASS,-AA', ];

    or

    [ APPNAME => 'Sanfrancisco', PRGNAME => 'MLSLogin', ARGUMENTS => join(', ', '-ASS', '-AA'), ];
Re: posting with HTTP::Request::Common
by dorko (Prior) on Nov 07, 2006 at 01:35 UTC
    While ikegami tells you how to do it, I'll tell you that I had to add the following line to the end of your script to see what was going on:

    print $req->as_string;

    Cheers,

    Brent

    -- Yeah, I'm a Delt.