in reply to Yet another question on POSTing with LWP

I added some more reporting to the error case of your script, mostly

print $resp->as_string()
, and what I got back was an 500 internal server error. This means most likely, that you didn't supply all parameters needed for the request. Whenever I want to automate using a website, I set up a proxy to log all transfer going back and forth between the two connection points. This makes it easier for me to replicate the whole situation and not to miss out on any field that might be necessary.

When I look at http://www.usps.com/ncsc/lookups/lookup_zip+4.html, the original webpage, there are many more fields to fill out :

<FORM NAME="Table1FORM" ACTION="/cgi-bin/zip4/zip4inq2" METHOD=POST> <INPUT TABINDEX="1" ID="Firm" TYPE="text" NAME="Firm" VALUE="" SIZE=30 + MAXLENGTH=30 > <INPUT TABINDEX="2" ID="Urbanization" TYPE="text" NAME="Urbanization" +VALUE="" SIZE=30 MAXLENGTH=30> <INPUT TABINDEX="3" ID="Delivery Address" TYPE="text" NAME="Delivery A +ddress" VALUE="" SIZE=30 MAXLENGTH=40 > <INPUT TABINDEX="4" ID="City" TYPE="text" NAME="City" VALUE="" SIZE=30 + MAXLENGTH=30> <INPUT TABINDEX="5" ID="State" TYPE="text" NAME="State" VALUE="" SIZE= +2 MAXLENGTH=2 > <INPUT TABINDEX="6" ID="Zip Code" TYPE="text" NAME="Zip Code" VALUE="" + SIZE=10 MAXLENGTH=10 > <INPUT TABINDEX="7" TYPE="submit" NAME="Submit" VALUE="Process" ID="Fo +rmsButton2"> </FORM>

I would send all of them, even with empty content, because the CGI might be very badly written and expect all those fields to be present. But the best bet is always to use a dump of that session via a small proxy to see what fields with which content are actually sent.

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Re: Yet another question on POSTing with LWP
by Shizzle (Novice) on Apr 23, 2002 at 13:14 UTC
    You're exactly right! I won't take as_string() for granted anymore. Big ups for getting back to me promptly.