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

Hello again Monks,

Some of you may know of the form on the USPS website that enables you to check addresses:

http://www.usps.com/ncsc/lookups/lookup_zip+4.html

which, in turn runs the CGI script

http://www.usps.com/cgi-bin/zip4/zip4inq2
Around a month ago, I wrote a perl script using LWP to check a list of addresses automatically. Just today, I ran the script again and got this reponse:

HTTP/1.0 302 (Found) Not Allowed Location: http://148.129.65.3:80/fwauthredirect148.129.65.9id000386429 +5 Content-Length: 120 Content-Type: text/html Client-Date: Wed, 15 May 2002 15:21:08 GMT Client-Peer: 56.0.78.101:80 Your request is being redirected to :<a href="http://148.129.65.3:80/f +wauthredirect148.129.65.9id0003864295">here</a>.

Assuming my script was accessing a port other than 80, I modified my script to include the URL:

http://www.usps.com:80/cgi-bin/zip4/zip4inq2
But I got the same 302 Not Allowed message. Does this mean it is now impossible for me to access the CGI script via LWP? I always thought any CGI script you can access via a form on a web page can be accessed with LWP. Please enlighten. Thanks in advance for your help.

Replies are listed 'Best First'.
Re: POST with LWP yields HTTP 302 Not Allowed - Too bad for me?
by dsheroh (Monsignor) on May 15, 2002 at 15:42 UTC
    No, it means that your request was being redirected to http://148.129.65.3:80/fwauthredirect148.129.65.9id0003864295 and you need to resubmit it to that URI.

    When your browser gets a 302 (client-side redirect) message, it automagically follows it without bothering you. When you use LWP, you're taking control of things at a lower level, so you have to notice the 302, get the returned Location: header, and resubmit the request to that address yourself.

      Thanks for your reply, although I'm still misisng it. I ran the program again, went down to the line that had the "Location:" header, and copied the redirection URI into my code, which is below:

      #!/opt/gnu-irix/bin/perl use strict; use HTTP::Request::Common; use LWP::UserAgent; my $ua = new LWP::UserAgent; #my $formurl = 'http://www.usps.com:80/cgi-bin/zip4/zip4inq2'; my $formurl = 'http://148.129.65.3:80/fwauthredirect148.129.65.9id0003869786'; my $formdata = [ 'Firm' => '', 'Urbanization' => '', 'Delivery Address' => '100 Southland Vlg', 'City' => '', 'State' => '', 'Zip Code' => '36079-3044', 'Submit' => 'Process' ]; print $formurl, "\n"; my $resp = $ua->request(POST $formurl, $formdata); if ($resp->is_success()) { print $resp->content(); } else { print "Problem\n\n", $resp->as_string(); }

      Running the program generated a similar response:

      HTTP/1.0 302 (Found) Not Allowed Location: http://148.129.65.3:80/fwauthredirect148.129.65.9id000386993 +7 Content-Length: 120 Content-Type: text/html Client-Date: Wed, 15 May 2002 15:57:42 GMT Client-Peer: 56.0.78.101:80 Your request is being redirected to :<a href="http://148.129.65.3:80/f +wauthredirect148.129.65.9id0003869937">here</a>.

      It appears that I simply got redirected again. Please advise. Thanks.

Re: POST with LWP yields HTTP 302 Not Allowed - Too bad for me?
by jsprat (Curate) on May 15, 2002 at 16:24 UTC
    'fwauthredirect' is a message from your firewall (FW1). Does this same error happen when running the script with a direct connection? 56.0.78.101 is the ip address of usps.com, I'm assuming 148.129.65.3 (or 9) is the firewall's ip. You should probably talk to whoever administers the firewall.
      While talking to my sys admin, it dawned on me that our firewall had not authenticated me from the account where the perl scripts were written. See, when I was trying to figure out why I could use my browser and not LWP, I was surfing with IE on my local PC. So, from the Unix account where my perl scripts were, I fired up Netscape and typed www.usps.com. I supplied the firewall with my username and password, ran the perl script again, and got the desired results. Thanks to everyone for your feedback.
        It seems now the Post office doesn't let this work anymore:

        HTTP/1.1 405 Method Not Allowed
        Connection: close
        Date: Wed, 17 Mar 2010 18:07:28 GMT
        Server: Netscape-Enterprise/6.0
        Vary: Accept-Encoding
        Allow: HEAD, GET
        Content-Length: 124
        Content-Type: text/html
        Client-Date: Wed, 17 Mar 2010 18:07:27 GMT
        Client-Peer: 96.16.57.188:80
        Client-Response-Num: 1
        Title: Method Not Allowed