大家知道目前表单提交的方式有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代码发出的:
<form action="http://localhost:8080/cgi-bin/tech/method.cgi" method="GET">
<input type="text" size="10" value="GET" name="GET">
<input type=submit value="GET方式">
</form>
这个请求已经超出了我们研究的范围,我们只研究其中的第一行。其中,第一个"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代码,它将会出现什么问题呢?
<form action="http://localhost:8080/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>
这个代码在很多程序上可能用到过,但是大多数人不会好好的想一想,究竟哪些内容是以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混发!
/***********************************************************************/
以上是在优快云技术中心看到的对POST/GET方式的简单分析,看过之后对表单的提交可以有一个较为清晰地理解,另外,我也对jigsaw中对http请求的处理过程进行了研究,通过截获http应答,清楚了解了http协议应答内容的格式,以下是对jigsaw欢迎页面请求的应答内容:
HTTP/1.1 200 OK
Date: Tue, 19 Oct 2010 09:30:27 GMT
Content-Length: 3236
Content-Location: http://localhost:8001/Overview.html
Content-Type: text/html
Etag: "mvanct:157ptcu5v"
Last-Modified: Tue, 19 Oct 2010 09:30:27 GMT
Server: Jigsaw/2.2.6
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.2 Strict//EN">
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="style/jigsaw.css">
</style>
<TITLE>Jigsaw Overview</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<P>
<A href="../"><IMG BORDER="0" SRC="/icons/WWW/w3c_home"
ALT="W3C" WIDTH="72" HEIGHT="48">
</A><IMG BORDER="0" SRC="/icons/jigsaw" WIDTH="212" HEIGHT="49"
ALT="Jigsaw">
<H1 class="title">
Jigsaw Overview
</H1>
<HR noshade width="70%" align="left">
<P>
This is your home page, served by <b>Jigsaw</b> !
<p> You can edit it as the file
<CODE><INSTDIR>/Jigsaw/Jigsaw/WWW/Overview.html</CODE>.
<P>
For further questions, comments, criticisms, a
<A HREF="mailto:www-jigsaw@w3.org">mailing list</A> is
available, to subscribe send email to <A
HREF="mailto:www-jigsaw-request@w3.org">
www-jigsaw-request@w3.org</A> with the word <I>subscribe</I>
in the subject. Before posting, you're welcome to check the
<A HREF="http://lists.w3.org/Archives/Public/www-jigsaw/threads.html">
mailing list archive</A>.
<p>
<H2>
Configuring the server
</H2>
<P>
As of 2.0.0, <B>Jigsaw</B>'s configuration is handled through
a full-blown Java application named <B>JigAdmin</B>. To run that
application, run the following commands:
<DIV class="box">
<PRE style="font-family: Helvetica; font-size: 10pt">Windows
set CLASSPATH=<INSTDIR>/Jigsaw/classes/jigsaw.jar;<INSTDIR>/Jigsaw/classes/jigadmin.jar;<INSTDIR>/Jigsaw/classes/sax.jar;<INSTDIR>/Jigsaw/classes/xp.jar;.
java org.w3c.jigadmin.Main -root <INSTDIR>/Jigsaw/Jigsaw http://<I>yourmachine</I>:8009/
Unix
export CLASSPATH=<INSTDIR>/Jigsaw/classes/jigsaw.jar:<INSTDIR>/Jigsaw/classes/jigadmin.jar:<INSTDIR>/Jigsaw/classes/<INSTDIR>/Jigsaw/classes/sax.jar:<INSTDIR>/Jigsaw/classes/xp.jar:.
java org.w3c.jigadmin.Main -root <INSTDIR>/Jigsaw/Jigsaw http://<I>yourmachine</I>:8009/</PRE></DIV>
<p> If you still use the old JigAdmin with the
following commands:
<DIV class="box">
<PRE style="font-family: Helvetica; font-size: 10pt">Windows
set CLASSPATH=<INSTDIR>/Jigsaw/classes/jigsaw.jar;<INSTDIR>/Jigsaw/classes/sax.jar;<INSTDIR>/Jigsaw/classes/xp.jar;.
java org.w3c.jigadm.Main -root <INSTDIR>/Jigsaw/Jigsaw http://<I>yourmachine</I>:8009/
Unix
export CLASSPATH=<INSTDIR>/Jigsaw/classes/jigsaw.jar:<INSTDIR>/Jigsaw/classes/sax.jar:<INSTDIR>/Jigsaw/classes/xp.jar
java org.w3c.jigadm.Main -root <INSTDIR>/Jigsaw/Jigsaw http://<I>yourmachine</I>:8009/</PRE></DIV>
<P>
<H2>
More Infos
</H2>
<UL>
<LI>
<A HREF="/Doc/">Jigsaw User's Guide</A>
<LI>
<A HREF="RelNotes.html">Latest Release Notes</A>
<LI>
<A HREF="http://www.w3.org/Jigsaw/">Jigsaw's home page
</A>(remote)
<LI>
<A HREF="http://jigsaw.w3.org/">Demo site</A> (remote)
</UL>
<P>
<HR noshade>
Enjoy !<BR>
<A HREF="mailto:jigsaw@w3.org">Jigsaw Team</A>
</BODY>
</HTML>