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

In reply to Re: Yet another question on POSTing with LWP by Corion
in thread Yet another question on POSTing with LWP by Shizzle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.