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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#!/usr/bin/perl
$server = 'www.weather.com';
$document='/cgi-bin/uncgi/ city_searc h.pl';
$content = 'go city&city_destination=bost on';
$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_ato n($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-url encoded
";
print(S $request);
print(S $content);
$/ = "\r\n\r\n";
$_ = <S>;
print $_;
undef $/;
print <S> if( /Content-type:\s*text\// );
$server = 'www.weather.com';
$document='/cgi-bin/uncgi/
$content = 'go city&city_destination=bost
$port = 80;
use Socket;
$tcp = getprotobyname('tcp');
socket(S, PF_INET, SOCK_STREAM, $tcp) || die "socket: $!";
if ($server =~ /^[0-9]+\.[0-9]+\.[0-9]+\.
$addrs = pack('C4', split(/\./,$server));
}else{
$addrs = (gethostbyname($server))[4
}
$remote = sockaddr_in($port,inet_ato
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-url
";
print(S $request);
print(S $content);
$/ = "\r\n\r\n";
$_ = <S>;
print $_;
undef $/;
print <S> if( /Content-type:\s*text\// );
http://www.weather.com/weather/us/cities/MI_Detroit.html
So couldn't you just send your user to that same url?