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,
griffgg8
Here's part of the code:
Any help will be greatly appreciated.
I have tried everything I can think of.
Thanks in advance,
griffgg8
Here's part of the code:
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;
[COLOR=red]
$response = $ua->request(POST '[URL unfurl="true"]http://www.website.com/DT/login.asp',[/URL]
[
username => 'xxxxxxxxxxxxxxxxx',
password => 'xxxxxxxxxxxxxxxxx'
],
[
HTTP-EQUIV => '1.1',
Host => '[URL unfurl="true"]www.website.com',[/URL]
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 => '[URL unfurl="true"]http://www.website.com/DT/login.asp',[/URL]
Cookie => 'ASPSESSIONIDAQDSTCTD=GKDOMDBDEKCPAJEIPOODFIAA; BTC=LogFlag=1&ContactID=C6UJ9A007HO8',
Location => '/dt/default.asp',
Previous => '[URL unfurl="true"]http://www.website.com/DT/login.asp',[/URL]
Content-Type => 'application/x-www-form-urlencoded'
]
);
[/color]
$original_response_code = $response->code;
[COLOR=blue]if ($original_response_code =~ /302/)
{[/color]
$referral = LWP::UserAgent->new;
$referral_uri = $response->header('Location');
local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
$base = $response->base;
$referral_uri = $HTTP::URI_CLASS->new($referral_uri, $base)->abs($base);
[COLOR=red] $response2 = $referral->request(GET $referral_uri);[/color]
printf " response2=%s\n", $response2;
[COLOR=blue]}[/color]
else
{
$content = $response->content();
printf " else contents=%s\n", $content;
};
exit (0);