HTML部分:
<html>
<head>
<title>Get-Post</title>
</head>
<body>
<form action="/cgi-bin/tech/method.cgi" method="GET">
<input type="text" size="10" value="GET" name="GET">
<input type=submit value="GET方式">
</form>
<form action="/cgi-bin/tech/method.cgi" method="POST">
<input type="text" size="10" value="POST" name="POST">
<input type=submit value="POST方式">
</form>
<form action="/cgi-bin/tech/method.cgi?GET=GET" method="POST">
<input type="text" size="10" value="POST" name="POST">
<input type=submit value="GET/POST方式">
</form>
<form action="/cgi-bin/tech/method.cgi?name=Hackfan&age=16&email=hackfan@163.net" method="POST">
<input type="text" size="10" value="Suzhou" name="address">
<input type="text" size="10" value="msger.net" name="homepage">
<input type="text" size="10" value="106814" name="qq">
<input type=submit value="复杂GET/POST方式">
</form>
</body>
</html>
Perl部分:
#!/usr/bin/perl
$|=1;
print "Content-type:text/html\n\n";
print "发送方式:$ENV{'REQUEST_METHOD'}<br>\n";
if(read(STDIN,$POST,$ENV{'CONTENT_LENGTH'})){
print "POST得到的数据:$POST<br>\n";
}
if($GET=$ENV{'QUERY_STRING'}){
print "GET得到的数据:$GET<br>\n";
}
$METHOD="POST";
for($i=0;$i<=1;$i++){
foreach(split(/&/,$$METHOD)){
$_=~s/\+//g;
($name,$value)=split(/=/,$_);
$name=~s/%([a-fA-f0-9][a-fA-f0-9])/pack("C",hex($1))/eg;
$value=~s/%([a-fA-f0-9][a-fA-f0-9])/pack("C",hex($1))/eg;
$$METHOD{$name}=$value;
}
$METHOD="GET";
}
$METHOD="POST";
for($i=0;$i<=1;$i++){
print "Hash形式的$METHOD数据遍历:<br>\n";
foreach(keys %{$METHOD}){
print "\$".$METHOD."{".$_."}=$$METHOD{$_}<br>\n";
}
print "<br>\n";
$METHOD="GET";
}
exit;