Hello,

Issue with POST

I need to create spider for this URL.

Get is getting the loggin page

I did POST but I'm not logged in.

Probably I'm not using cookies the correct way.

Thanks for help.

-Jim-

 

use LWP::RobotUA;

use HTTP::Request::Common qw(POST);

use HTTP::Cookies;

use Data::Dumper;

use HTTP::Cookies;

 

# get http://www.governmentsecurity.org/forum/index.php?act=Login&CODE=00

# create robot

$robot = LWP::myRobotUA->new('Mozilla/5.0 (Windows XP; U) Opera 6.0 [en]', "\@");

$robot->credentials(

'www.governmentsecurity.org:80',

'forum/index.php?act=Login&CODE=00',

'XXX' => 'XXX'

);

$robot->cookie_jar( HTTP::Cookies->new(

'file' => 'cookies.lwp',

# where to read/write cookies

'autosave' => 1,

# save it to disk when done

));

 

# temporarily set delay to 0 minutes instaed of 10

$robot ->delay(0);

my $url_string = 'http://www.governmentsecurity.org/forum/index.php?act=Login&CODE=00';

# specify directory

my $request = HTTP::Request->new('GET', $url_string);

# carry out network access

my $response = $robot->request($request);

#my $response = $ua->request($request) or print "Failed to send request: $!";

# error check

$doc = $response->content(); # document OK

#$response->is_success() || warn $response->message();

if ($response->is_success)

{

print $response->content;

} else

{

print "Error: " . $response->status_line . "\n";

my $ERRFILE;

open (ERRFILE, ">>$ErrFile") || die "cannot open the err file";

print ERRFILE "$url_string\n";

close (ERRFILE);

}

$doc =~/action=""/i;

$url = "">

my @temp = ['UserName' => 'XXX',

'PassWord' => 'XXX',

'CookieDate' => '1',

'Privacy' => '<OFF>',

];

 

my $result = sendPost ($url, @temp);

$result =~/action="">/i;

sleep (1);

exit;

sub sendPost ($$)

{

my $url = "">

my @temp = $_[1];

my $DEBUG=1 if $ARGV[0]=~/-D(ebug)?/i;

#my $ua = new LWP::UserAgent or die "new LWP::UserAgent: $!";

$ua = LWP::myRobotUA->new('Mozilla/5.0 (Windows XP; U) Opera 6.0 [en]', "\@");

#$ua->agent('Mozilla/5.0');

$ua->cookie_jar( HTTP::Cookies->new(

'file' => 'cookies.lwp',

# where to read/write cookies

'autosave' => 1,

# save it to disk when done

));

#$ua->cookie_jar(HTTP::Cookies->new());

my $req = POST $url, @temp or die "new HTTP::Request POST: $!";

print Data::Dumper->Dump([\$ua], [qw($ua)]) if $DEBUG;

print Data::Dumper->Dump([\$req], [qw($req)]) if $DEBUG;

my $res = $ua->request($req);

my $content = $res->as_string;

print $content if $DEBUG;

print $content;

return $content;

}

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

_______________________________________________
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to