Link to home
Start Free TrialLog in
Avatar of jmills99
jmills99

asked on

How to create a post form, without using a form.(PERL)

Here's where I'm at:

I have all the information a user wants submitted to a form, and now, using PERL, I need to create the correct headers and send them to an outside site.

For example:  I know the user wants to know the weather in Detroit, I want to pass information to the Weather Channel just as if it had come from the www.weather.com POST form in the first place.  

I have this working for GET forms, I just call the form-submit URL and ?append the variables.  I want to know how to do this for POST forms.

Can anyone please walk or pseudocode (Heck, or even show code!) me through this?

JMills99
Avatar of ozo
ozo
Flag of United States of America image

It looks like their POST form just directs you to another url, e.g.
http://www.weather.com/weather/us/cities/MI_Detroit.html
So couldn't you just send your user to that same url?

ASKER CERTIFIED SOLUTION
Avatar of faster
faster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#!/usr/bin/perl

$server = 'www.weather.com';
$document='/cgi-bin/uncgi/city_search.pl';
$content = 'go city&city_destination=boston';
$port = 80;

use Socket;
$tcp = getprotobyname('tcp');

socket(S, PF_INET, SOCK_STREAM, $tcp) || die "socket: $!";

if ($server =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
    $addrs = pack('C4', split(/\./,$server));
}else{
    $addrs = (gethostbyname($server))[4];
}

$remote = sockaddr_in($port,inet_aton($server));
connect(S, $remote) or die "can't connect to $server because $!";

select(S); $| = 1;
select(STDOUT); $| = 1;

$request = "POST $document HTTP/1.0
User-Agent: LWP-request/1.20
Content-Length: ".length($content)."
Content-Type: application/x-www-form-urlencoded

";

print(S $request);
print(S $content);

$/ = "\r\n\r\n";
$_ = <S>;
print $_;

undef $/;
print <S> if( /Content-type:\s*text\// );