Emulating POST !!!
Paulo Castro (ee96123@fe.up.pt)
Wed, 07 Mar 2001 18:48:58 +0000
The code above emulates a Post operation.
I've tested it and it works fine, it does the post except for the "print
$response->content" where i get the error of malformed header from
script. Bad header=<html>:
/home/facultis/facultis-www/cgi-bin/postform.cgi. I can't return
nothing!
Initially i thought that it coul be my mistake, the script i was calling
could be returning wrong html. But i tested it with the url above and it
just guives me the same error.
What i'm i missing here...?
Thanx
#!/usr/bin/perl -w
use strict;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
my $url = 'https://netbi.sapo.pt/login';
#open (Z,">/tmp/t3.txt");
# Create new UserAgent object (browser)
my $ua = LWP::UserAgent->new();
# Give the browser a name
$ua->agent("Mozilla/4.0");
# Create HTTP POST request
my $request = HTTP::Request->new(POST => $url);
$request->content_type('application/x-www-form-urlencoded');
$request->content('rs=http://sms.sapo.pt/&rf=http://sms.sapo.pt/&login=teste&password=teste');
# Execute HTTP request
my $response = $ua->request($request);
# Check success
if ($response->is_success) {
print $response->content;
#print Z $response->as_string;
} else {
print "Error getting document: ", $response->status_line,"\n";
#close(Z);
}