深入研究表单提交方式:GET/POST
2010-11-22 19:24
435 查看
深入研究表单提交方式:GET/POST
Hackfan
本文平台:Windows 2000 Professional + Apache 1.3.17 + Perl 5.6.1 + Internet Explorer 5.00.2920.0000
大家知道目前表单提交的方式有GET和POST。我在这里不多说什么,给大家看一个以GET方式提交的表单的请求:
GET /cgi-bin/tech/method.cgi?GET=GET HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Referer: http://localhost//other.html
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Host: localhost:8080
Connection: Keep-Alive
这个请求是我们通过这个HTML代码发出的:
####代码结束####
好了,我要说的是,搞这个研究究竟有什么意义呢?
意义是:让你知道,用户提交的数据哪些是用POST方式,哪些使用GET方式的!
其实我上面那段Perl代码已经包括了很多的技术。你通过阅读就可以知道%GET里面放的是用GET方式提交的,%POST同理!
如果你对我编写的Perl代码感兴趣,欢迎切磋:QQ:106814。至于我如何获得IE发送来的请求的,我要说我是用Perl编的一个Server监听8080端口,我是不是像欧姆一样搞研究大多东西都自己编写(当然,让我编写一个操作系统就有点难度了,不过WebServer凑合)?开玩笑呢!
Hackfan
本文平台:Windows 2000 Professional + Apache 1.3.17 + Perl 5.6.1 + Internet Explorer 5.00.2920.0000
大家知道目前表单提交的方式有GET和POST。我在这里不多说什么,给大家看一个以GET方式提交的表单的请求:
GET /cgi-bin/tech/method.cgi?GET=GET HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Referer: http://localhost//other.html
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Host: localhost:8080
Connection: Keep-Alive
这个请求是我们通过这个HTML代码发出的:
这个请求已经超出了我们研究的范围,我们只研究其中的第一行。其中,第一个"GET"说出了提交的方式,是以GET方式提交的;中间的就是提交给服务器上哪个程序,前面一部分"/cgi-bin/tech/method.cgi"就是我们HTML的form中action的内容,而后面的"GET=GET"就是HTML的form中,input的内容:我们发现IE已经把这个表单的内容转换成特定格式了。在Perl中,通过$GET=$ENV{'QUERY_STRING'}获得以GET发送的数据。 我们再看一个以POST方式提交的表单的请求: POST /cgi-bin/tech/method.cgi HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms- powerpoint, application/vnd.ms-excel, application/msword, */* Referer: http://localhost//other.html Accept-Language: zh-cn Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) Host: localhost:8080 Content-Length: 9 Connection: Keep-Alive POST=POST 同样给出HTML:<form action="http://localhost:8080/cgi-bin/tech/method.cgi" method="POST"> <input type="text" size="10" value="POST" name="POST"> <input type=submit value="POST方式"> </form>
我们发现其中的数据跑到了最下面。在Perl中,通过read(STDIN,$POST,$ENV{'CONTENT_LENGTH'})获得以POST发送的数据。我记得GET发送数据最多只能1024字节,而POST好像很大很大!
思考:如果我有这么一段HTML代码,它将会出现什么问题呢?这个代码在很多程序上可能用到过,但是大多数人不会好好的想一想,究竟哪些内容是以GET发送的,哪些内容是以POST发送的。我们看看它的请求是什么: POST /cgi-bin/tech/method.cgi?GET=GET HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms- powerpoint, application/vnd.ms-excel, application/msword, */* Referer: http://localhost//other.html Accept-Language: zh-cn Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) Host: localhost:8080 Content-Length: 9 Connection: Keep-Alive POST=POST 哈!原来是以POST发送的。但是,你一定发现了有一部分数据放在了第一行,就是和GET的情况一样的。其实这个例子很典型,是POST和GET混发! 不相信你在Perl中,用read(STDIN,$POST,$ENV{'CONTENT_LENGTH'})和$GET=$ENV{'QUERY_STRING'}看看,到底哪个里面有"GET=GET"这个数据。 我给大家提供设备,大家自己去研究研究: 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部分:
#!c:\perl\bin\perl.exe
$|=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;
####代码结束####
好了,我要说的是,搞这个研究究竟有什么意义呢?
意义是:让你知道,用户提交的数据哪些是用POST方式,哪些使用GET方式的!
其实我上面那段Perl代码已经包括了很多的技术。你通过阅读就可以知道%GET里面放的是用GET方式提交的,%POST同理!
如果你对我编写的Perl代码感兴趣,欢迎切磋:QQ:106814。至于我如何获得IE发送来的请求的,我要说我是用Perl编的一个Server监听8080端口,我是不是像欧姆一样搞研究大多东西都自己编写(当然,让我编写一个操作系统就有点难度了,不过WebServer凑合)?开玩笑呢!
相关文章推荐
- 深入研究表单提交方式:GET/POST
- 深入研究表单的提交方式:get and post
- 深入研究表单提交方式:GET/POST
- javaseday32(画中画 表单 post get 提交方式)
- 表单中多个请求参数名字相同,服务器到底获取的是哪个请求参数的值,表单的action和get和post提交方式的关系以及提交数据的不同点
- 提交表单--get与post方式
- 表单提交中Get和Post方式的区别 .
- 表单的提交方式:get和post
- 表单的提交方式:get和post
- 网站设计的表单提交用POST方式还是GET方式?
- 表单提交中get和post方式的区别
- CGI提交表单的两种方式POST与GET
- [网络收集]form表单提交方式post和get,Request.QueryString,Request.Form
- 通过GET和POST方式提交表单
- HTML【2】表单提交与服务层的模拟(具体解释get与post提交方式的不同)
- 提交Form表单,POST和GET方式的传值问题。
- 表单的提交方式:get和post
- 表单的提交方式:get和post
- 表单提交方式中的get和post有什么区别?
- 表单提交中Get和Post方式的区别及EncType表明提交数据的格式详解