V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
oldgun
V2EX  ›  问与答

有人能总结一下什么时候用GET,什么时候用POST吗?

  •  
  •   oldgun · 2011-04-19 23:29:51 +08:00 via iPad · 12139 次点击
    这是一个创建于 4767 天前的主题,其中的信息可能已经有所发展或是发生改变。
    不要说用POST就可以这样的废话。谢谢!
    14 条回复    1970-01-01 08:00:00 +08:00
    qichangxing
        1
    qichangxing  
       2011-04-20 00:26:41 +08:00
    获取参数或者短小的内容时用 GET,如 ?id=5 或者 ?title=abc&url=http...
    获取大断的内容用 POST,通常表单用 POST 方式提交数据。
    icyflash
        2
    icyflash  
       2011-04-20 00:34:34 +08:00
    最简单的分类:提交用POST,获取用GET。
    1212e
        3
    1212e  
       2011-04-20 00:37:33 +08:00
    lz这态度... 给楼上的童鞋补充一点,post还有隐藏url参数的作用 比如登陆
    这种问题高手们肯定懒得回答...多google吧
    darcy
        4
    darcy  
       2011-04-20 00:41:55 +08:00
    对于增删查三种情况
    对数据有变更的请求(增删)用post
    普通情况下的获取信息(查)用get
    ajax多次获取同一url信息不打时间戳时用post
    iwinux
        5
    iwinux  
       2011-04-20 00:44:21 +08:00
    按照Rails里的惯例:

    1. GET 对应的是“获取数据”,比如搜索框用的是 GET

    2. POST 对应的是“新增数据”,比如发贴,回复的 form 用的是 POST

    3. PUT 对应的是“修改数据”,这个目前可能还用得不多,Rails里是用 POST 来模拟的。

    4. DELETE - 顾名思义。这个在 Rails 里是用 javascript 实现的。
    wenhuacn
        6
    wenhuacn  
       2011-04-20 14:00:59 +08:00
    这个问题不如问google
    @iwinux 这个是rails 符合REST 的规范
    GordianZ
        7
    GordianZ  
    MOD
       2011-04-20 14:05:22 +08:00
    不要说用Google就可以找到答案的废话。谢谢!
    http://lmgtfy.com/?q=what%27s+the+difference+between+post+and+get
    oldgun
        8
    oldgun  
    OP
       2011-04-20 19:51:00 +08:00
    @qichangxing @icyflash @1212e @darcy @iwinux @wenhuacn @GordianZ
    感谢诸位,发帖前我预想了几个答案,现在看来基本齐了。
    1、有人会说我态度差;
    2、总有人喜欢让提问的人问google,你不如让我去看rfc2616好了;
    3、有人会认真回答,尽管不够全面或者不够正确;
    4、没有人的回答非常系统。
    提这个问题是因为我觉得这里大部分人是搞web的,这个应该很多人知道。
    如论如何,我的目的达到了,谢谢诸位,特别是认真回帖的人!
    ps:是不是很乱?
    dreampuf
        9
    dreampuf  
       2011-04-20 20:01:31 +08:00
    认真你就输的游戏少玩为好.
    1212e
        10
    1212e  
       2011-04-20 20:06:14 +08:00
    @oldgun
    别人无偿回答你的问题 , 你还嫌不够全面系统正确? 都不理你你才高兴是吧...
    既然你都知道 干嘛不发出来分享? 让我们看看什么叫 全面!!系统!!正确!! 的答案?
    ps 你不是不爱google吗? 别发google能搜到的喔~~
    dreamer
        11
    dreamer  
       2011-04-20 20:20:09 +08:00
    @oldgun 这位老师,您来错地方了,出门右转是教务处,那里才是您编写试卷的地方。
    leogray
        12
    leogray  
       2011-04-21 19:54:06 +08:00
    楼主,二。
    oldgun
        13
    oldgun  
    OP
       2011-04-27 19:19:12 +08:00
    @leogray 请问我能回复你2b吗?
    dcoder
        14
    dcoder  
       2013-01-31 03:29:56 +08:00
    <Head First HTML>书上的原话:

    There’s a couple of big differences that really matter. If you want users to be able to bookmark pages that are the result of submitting a form, then you have to use GET, because there is no way to bookmark a page that has been returned as a result of a POST. When would you want to do that? Say you have a Web application that returns a list of search results; you might want users to be able to bookmark those results so they can see them again without having to fill out a form.

    On the other hand, if you have a Web application that processes orders, then you wouldn’t want users to be able to bookmark the page. (Otherwise, every time they returned to the bookmark, the order would be resubmitted.) A situation when you’d never want to use a GET is when the data in your form is private, like a credit card or a password. Because the URL is in plain view, the private information is easily found by others if they look through your browser history or if the GET somehow gets bookmarked. Finally, if you use a <textarea>, you should use POST, because you’re probably sending a lot of data. GET requests have a limit of 256 characters; POST has no limit on the size of the data package you send.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3769 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:50 · PVG 12:50 · LAX 21:50 · JFK 00:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.