Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PERL cgi Status Code 302 problem

PERL cgi Status Code 302 problem

PERL cgi Status Code 302 problem

I have been trying for a few weeks to retrieve a html page programatically that requires a username/password.  Normally, the username/password is submitted via the POST method, the response from the server is Status Code 302 (temporaryly moved).  The redirection is completed using the GET method and the correct page pops up.  When I do it programatically, I do NOT get the correct page (it defautlts to asking for the username and password again).  

Any help will be greatly appreciated.
I have tried everything I can think of.

Thanks in advance,


Here's part of the code:


use LWP::UserAgent;
use HTTP::Headers;
use HTTP::Status;
use HTTP::Request::Common;
use HTTP::Response;
use URI::URL;
use URI;

$ua = LWP::UserAgent->new;

$response = $ua->request(POST     'http://www.website.com/DT/login.asp',
        username => 'xxxxxxxxxxxxxxxxx',
        password => 'xxxxxxxxxxxxxxxxx'
        HTTP-EQUIV => '1.1',
        Host     => 'www.website.com',
        User-Agent => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
        Accept     => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*',
        Accept-Language    => 'en-us',
        Accept-Encoding => 'gzip, deflate',
        Proxy-Connection => 'Keep-Alive',
        Pragma         => 'no-cache',
        Referer                 => 'http://www.website.com/DT/login.asp',
        Cookie                 => 'ASPSESSIONIDAQDSTCTD=GKDOMDBDEKCPAJEIPOODFIAA; BTC=LogFlag=1&ContactID=C6UJ9A007HO8',
        Location    => '/dt/default.asp',
        Previous                => 'http://www.website.com/DT/login.asp',
        Content-Type     => 'application/x-www-form-urlencoded'

$original_response_code = $response->code;
if ($original_response_code =~ /302/)

    $referral       = LWP::UserAgent->new;
    $referral_uri     = $response->header('Location');
    $base         = $response->base;
    $referral_uri     = $HTTP::URI_CLASS->new($referral_uri, $base)->abs($base);
    $response2 = $referral->request(GET $referral_uri);
    printf "   response2=%s\n", $response2;
    $content = $response->content();
    printf  "   else contents=%s\n", $content;
exit (0);

RE: PERL cgi Status Code 302 problem


I do not know the LWP module, so I can not help to correct it.

But the problem must be somewhere around the new :


    $referral       = LWP::UserAgent->new;
    # ...
    $response2 = $referral->request(GET $referral_uri);
So you create a completely new request without passing forward the cookie(s) containing the authentication's result, received from the previous request.


RE: PERL cgi Status Code 302 problem

I tried "clone"ing the original $ua by replacing "$referral = LWP::UserAgent->new;" with "$referral = $ua->clone;" and got the same results.  Got any other ideas?



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close