Re: Emulating POST !!!

Christoph Wernli (cw@dwc.ch)
Wed, 07 Mar 2001 21:19:38 +0100


Paulo Castro wrote:
> 
> 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...?

At least one parameter:

<input type=hidden name=ou value="isto_e_para_devolver">

Another problem probably arises with the use of https (never tried it); check the
archives, there should be something noteworthy there.

Cheers,

-Christoph

> #!/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);
> }