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

I have created a code from which I am getting and 302 Object Moved error: Here is my code:
use HTML::Entities; # encode and decode things like <, >, and & use HTML::Form; # for form processing use HTTP::Cookies; # keep track of cookie use HTTP::Request::Common; use LWP::UserAgent; # pretend we are a browser use Data::Dumper; use Exporter; use LWP::Debug qw(+); use strict; my $url = 'https://interddt.com/cqweb/logon/default_content.asp'; my $browser = LWP::UserAgent->new; my $response = $browser->request(POST "$url", [ DatabaseName => 'TECH' +, User => '<user id>', Password => '<password>' ]); die "Error at $url\n ", $response->status_line, "\n Aborting" unless $response->is_success; print "Whee, it worked! I got that ", $response->content_type, " document!\n";
And here is the output of the LWP debug trace from this code
#> perl ./test.pl LWP::UserAgent::new: () LWP::UserAgent::request: () LWP::UserAgent::simple_request: POST https://dtinterddt.digitalthink.c +om/cqweb/logon/default_content.asp LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::http::request: POST /cqweb/logon/default_content.asp HT +TP/1.0 Host: dtinterddt.digitalthink.com User-Agent: libwww-perl/5.53 Content-Length: 48 Content-Type: application/x-www-form-urlencoded LWP::Protocol::http::request: POST /cqweb/logon/default_content.asp HT +TP/1.0 Host: dtinterddt.digitalthink.com User-Agent: libwww-perl/5.53 Content-Length: 48 Content-Type: application/x-www-form-urlencoded LWP::Protocol::http::request: reading response LWP::Protocol::http::request: HTTP/1.1 302 Object moved Server: Microsoft-IIS/5.0 Date: Mon, 06 Dec 2004 10:58:27 GMT Location: /cqweb/default_content.asp Connection: Keep-Alive Content-Length: 121 Content-Type: text/html Set-Cookie: CQWebUsrSettings=LOGON%5FUSER=dkhanna&LOGON%5FDBSET=2002%2 +52e05%252e00&LOGON%5FDB=TECH; expires=Mon, 27-Dec-2004 08:00:00 GMT; +path=/ LWP::Protocol::http::request: HTTP/1.1 302 Object moved LWP::Protocol::http::request: need more header data LWP::Protocol::collect: read 21 bytes LWP::Protocol::collect: read 100 bytes LWP::UserAgent::request: Simple response: Found Error at https://dtinterddt.digitalthink.com/cqweb/logon/default_conte +nt.asp 302 Object moved Aborting at ./test.pl line 16

2004-12-08 Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: 302 object moved error
by ikegami (Patriarch) on Dec 08, 2004 at 17:43 UTC

    302 is not an error, it's a redirect. To redirect POSTs automatically, do
    push @{ $browser->requests_redirectable }, 'POST';
    as per the LWP::UserAgent documentation.