develooper Front page | perl.libwww | Postings from March 2001

Emulating POST !!!

Thread Next
From:
Paulo Castro
Date:
March 7, 2001 12:11
Subject:
Emulating POST !!!
Message ID:
3AA68299.EC409789@fe.up.pt
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);
}




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About