免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 833 | 回复: 0
打印 上一主题 下一主题

get and post [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-01-09 08:57 |只看该作者 |倒序浏览
HTML表单Form中的getpost方法
在B/S应用程序中,前台与后台的数据交互,都是通过HTML中Form表单完成的。Form提供了两种数据传输的方式——get和post。虽然它们都是数据的提交方式,但是在实际传输时确有很大的不同,并且可能会对数据产生严重的影响。虽然为了方便的得到变量值,Web容器已经屏蔽了二者的一些差异,但是了解二者的差异在以后的编程也会很有帮助的。
Form中的get和post方法,在数据传输过程中分别对应了HTTP协议中的GET和POST方法。二者主要区别如下:
  1、Get是用来从服务器上获得数据,而Post是用来向服务器上传递数据。
  2、Get将表单中数据的按照variable=value的形式,添加到action所指向的URL后面,并且两者使用“?”连接,而各个变量之间使用“&”连接;Post是将表单中的数据放在form的数据体中,按照变量和值相对应的方式,传递到action所指向URL。
  3、Get是不安全的,因为在传输过程,数据被放在请求的URL中,而如今现有的很多服务器、代理服务器或者用户代理都会将请求URL记录到日志文件中,然后放在某个地方,这样就可能会有一些隐私的信息被第三方看到。另外,用户也可以在浏览器上直接看到提交的数据,一些系统内部消息将会一同显示在用户面前。Post的所有操作对用户来说都是不可见的。
  4、Get传输的数据量小,这主要是因为受URL长度限制;而Post可以传输大量的数据,所以在上传文件只能使用Post
  5、Get限制Form表单的数据集的值必须为ASCII字符;而Post支持整个ISO10646字符集。
  6、Get是Form的默认方法。

get and post
The get method
When you specify method="get" in your  tag, the information that enter into your form will be tacked on to the end of the action= address.
For example, go to
Yahoo!
and type computers in the search area. After you click the Search button, look at the Location area near the top of your browser window. It shows:
http://search.yahoo.com/bin/search?p=computers The first part in red is the action address. The part in green includes the word you typed. The neat part of the get method is that you don't have to even use a form to send the data. As a further experiment, in your browser, erase the word computers from the location area, and type printers instead. When it looks like what you see below, press Enter.
http://search.yahoo.com/bin/search?p=printers
The get method is agnostic -- it doesn't know (or care) where its input came from. In the first case, it came from Yahoo's search form. In the second case, it came from something you typed in the location area. You can even take the contents of the location area and cut and paste it into a hypertext link:
Search Yahoo for Printers
And it looks like this:
Search Yahoo for Printers

With all these advantages, why use any other method? Well, first, many servers will put an upper limit to how many characters you can tack on after the destination address. This upper limit is usually somewhere around 2000 bytes. Second, there are times when you just don't want to put the information in the location bar, which tells the whole universe, “Hey, look at what this guy typed!!!!”
The post method
The post method sends your data to the server “behind the scenes” by putting it on what computer folks call standard input. The information on your form won't appear in the location area, so the screen looks a bit cleaner. Furthermore, servers will put a larger upper limit on the number of bytes that can be transmitted via the post method; usually around 32000. Of course, the disadvantage of post is that you can't cut and paste the information into a link.
Which Should I Use?
Some scripts are designed to accept information only from the get method; others are designed to react only to post data. If this is the case, the webmaster and programmer you're working with will tell you which method to use. In the absence of any explicit instructions, we recommend post because it doesn't mess up the location area, and it will normally accept more data.



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/29515/showart_228599.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP