From what I can gather, there are three categories:
根据我的收集,有三类:
- Never use
GET
and usePOST
- Never use
POST
and useGET
- It doesn't matter which one you use.
切勿使用GET并使用POST
永远不要使用POST并使用GET
你使用哪一个并不重要。
Am I correct in assuming those three cases? If so, what are some examples from each case?
假设这三个案件我是否正确?如果是这样,每个案例的一些例子是什么?
27 个解决方案
#1
323
Use POST
for destructive actions such as creation (I'm aware of the irony), editing, and deletion, because you can't hit a POST
action in the address bar of your browser. Use GET
when it's safe to allow a person to call an action. So a URL like:
使用POST进行破坏性操作,例如创建(我知道讽刺),编辑和删除,因为您无法在浏览器的地址栏中点击POST操作。如果允许某人呼叫某个动作是安全的,请使用GET。所以像这样的URL:
http://myblog.org/admin/posts/delete/357
Should bring you to a confirmation page, rather than simply deleting the item. It's far easier to avoid accidents this way.
应该带您到确认页面,而不是简单地删除该项目。以这种方式避免事故要容易得多。
POST
is also more secure than GET
, because you aren't sticking information into a URL. And so using GET
as the method
for an HTML form that collects a password or other sensitive information is not the best idea.
POST也比GET更安全,因为您没有将信息粘贴到URL中。因此,使用GET作为收集密码或其他敏感信息的HTML表单的方法并不是最好的主意。
One final note: POST
can transmit a larger amount of information than GET
. 'POST' has no size restrictions for transmitted data, whilst 'GET' is limited to 2048 characters.
最后一点:POST可以传输比GET更多的信息。 'POST'对传输的数据没有大小限制,而'GET'限制为2048个字符。
#2
181
In brief
- Use
GET
forsafe and idempotent
requests - Use
POST
forneither safe nor idempotent
requests
使用GET来获得安全和幂等的请求
使用POST既不是安全请求也不是幂等请求
In details There is a proper place for each. Even if you don't follow RESTful principles, a lot can be gained from learning about REST and how a resource oriented approach works.
详细信息每个都有适当的位置。即使您不遵循RESTful原则,也可以从学习REST以及面向资源的方法如何工作中获得很多。
A RESTful application will
use GETs
for operations which are bothsafe and idempotent
.RESTful应用程序将使用GET进行安全和幂等操作。
A safe
operation is an operation which does not change the data
requested.
安全操作是不改变所请求数据的操作。
An idempotent
operation is one in which the result will be the same
no matter how many times you request it.
幂等操作是指无论您请求多少次,结果都是相同的操作。
It stands to reason that, as GETs are used for safe operations they are automatically also idempotent. Typically a GET is used for retrieving a resource (a question and its associated answers on stack overflow for example) or collection of resources.
按理说,由于GET用于安全操作,它们自动也是幂等的。通常,GET用于检索资源(例如,关于堆栈溢出的问题及其相关答案)或资源集合。
A RESTful app will use
PUTs
for operations which arenot safe but idempotent
.RESTful应用程序将使用PUT进行不安全但幂等的操作。
I know the question was about GET and POST, but I'll return to POST in a second.
我知道问题是关于GET和POST,但我会在一秒钟内回到POST。
Typically a PUT is used for editing a resource (editing a question or an answer on stack overflow for example).
通常,PUT用于编辑资源(例如,编辑有关堆栈溢出的问题或答案)。
A
POST
would be used for any operation which isneither safe or idempotent
.POST将用于任何既不安全也不是幂等的操作。
Typically a POST would be used to create a new resource for example creating a NEW SO question (though in some designs a PUT would be used for this also).
通常,POST将用于创建新资源,例如创建一个新的SO问题(尽管在某些设计中也会使用PUT)。
If you run the POST twice you would end up creating TWO new questions.
如果你运行POST两次,你最终会创建两个新问题。
There's also a DELETE operation, but I'm guessing I can leave that there :)
还有一个DELETE操作,但我猜我可以留下那里:)
Discussion
In practical terms modern web browsers typically only support GET and POST reliably (you can perform all of these operations via javascript calls, but in terms of entering data in forms and pressing submit you've generally got the two options). In a RESTful application the POST will often be overriden to provide the PUT and DELETE calls also.
实际上,现代Web浏览器通常只能可靠地支持GET和POST(您可以通过javascript调用执行所有这些操作,但就在表单中输入数据和按提交而言,您通常有两个选项)。在RESTful应用程序中,POST通常会被覆盖以提供PUT和DELETE调用。
But, even if you are not following RESTful principles, it can be useful to think in terms of using GET for retrieving / viewing information and POST for creating / editing information.
但是,即使您没有遵循RESTful原则,考虑使用GET检索/查看信息和POST来创建/编辑信息也是有用的。
You should never use GET for an operation which alters data. If a search engine crawls a link to your evil op, or the client bookmarks it could spell big trouble.
永远不要将GET用于改变数据的操作。如果搜索引擎抓取指向您的恶意操作的链接,或客户端书签,则可能会遇到大麻烦。
#3
70
Use GET if you don't mind the request being repeated (That is it doesn't change state).
如果您不介意重复请求(即它不会改变状态),请使用GET。
Use POST if the operation does change the system's state.
如果操作确实改变了系统的状态,请使用POST。
#4
63
Short Version
GET: Usually used for submitted search requests, or any request where you want the user to be able to pull up the exact page again.
GET:通常用于提交的搜索请求,或者您希望用户能够再次提取确切页面的任何请求。
Advantages of GET:
GET的优点:
- URLs can be bookmarked safely.
- Pages can be reloaded safely.
可以安全地为URL添加书签。
页面可以安全重新加载。
Disadvantages of GET:
GET的缺点:
- Variables are passed through url as name-value pairs. (Security risk)
- Limited number of variables that can be passed. (Based upon browser. For example, Internet Explorer is limited to 2,048 characters.)
变量作为名称 - 值对传递给url。 (安全风险)
可以传递的变量数量有限。 (基于浏览器。例如,Internet Explorer限制为2,048个字符。)
POST: Used for higher security requests where data may be used to alter a database, or a page that you don't want someone to bookmark.
POST:用于更高安全性请求,其中数据可用于更改数据库,或用于不希望某人加入书签的页面。
Advantages of POST:
POST的优点:
- Name-value pairs are not displayed in url. (Security += 1)
- Unlimited number of name-value pairs can be passed via POST. Reference.
名称 - 值对不会显示在url中。 (安全+ = 1)
可以通过POST传递无限数量的名称 - 值对。参考。
Disadvantages of POST:
POST的缺点:
- Page that used POST data cannot be bookmark. (If you so desired.)
使用POST数据的页面无法添加书签。 (如果你愿意的话。)
Longer Version
Directly from the Hypertext Transfer Protocol -- HTTP/1.1:
直接来自超文本传输协议 - HTTP / 1.1:
9.3 GET
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.
GET方法意味着检索由Request-URI标识的任何信息(以实体的形式)。如果Request-URI引用数据生成过程,则生成的数据应作为响应中的实体而不是过程的源文本返回,除非该文本恰好是过程的输出。
The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.
如果请求消息包括If-Modified-Since,If-Unmodified-Since,If-Match,If-None-Match或If-Range头字段,则GET方法的语义变为“条件GET”。条件GET方法请求仅在条件头字段描述的情况下传送实体。条件GET方法旨在通过允许刷新缓存的实体而不需要多个请求或传输客户端已经拥有的数据来减少不必要的网络使用。
The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.
如果请求消息包括Range头字段,则GET方法的语义变为“部分GET”。部分GET请求仅传输实体的一部分,如第14.35节所述。部分GET方法旨在通过允许完成部分检索的实体而不传输客户端已经拥有的数据来减少不必要的网络使用。
The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in section 13.
当且仅当它满足第13节中描述的HTTP缓存要求时,对GET请求的响应才是可缓存的。
See section 15.1.3 for security considerations when used for forms.
有关用于表单的安全注意事项,请参见第15.1.3节。
9.5 POST
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
POST方法用于请求源服务器接受请求中包含的实体作为Request-URI中Request-URI标识的资源的新下级。 POST旨在允许统一的方法来涵盖以下功能:
Annotation of existing resources;
现有资源的注释;
Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
在公告板,新闻组,邮件列表或类似的文章组中发布消息;
Providing a block of data, such as the result of submitting a form, to a data-handling process;
提供数据块,例如提交表单的结果,数据处理过程;
Extending a database through an append operation.
通过追加操作扩展数据库。
The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.
POST方法执行的实际功能由服务器确定,通常依赖于Request-URI。发布的实体从属于该URI,其方式与文件从属于包含它的目录相同,新闻文章从属于发布它的新闻组,或者记录从属于数据库。
The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.
POST方法执行的操作可能不会生成可由URI标识的资源。在这种情况下,200(OK)或204(No Content)是适当的响应状态,具体取决于响应是否包括描述结果的实体。
#5
27
The first important thing is the meaning of GET versus POST :
第一个重要的是GET与POST的含义:
- GET should be used to... get... some information from the server,
- while POST should be used to send some information to the server.
应该使用GET来...从服务器获取一些信息,
而POST应该用于向服务器发送一些信息。
After that, a couple of things that can be noted :
在那之后,可以注意到以下几点:
- Using GET, your users can use the "back" button in their browser, and they can bookmark pages
- There is a limit in the size of the parameters you can pass as GET (2KB for some versions of Internet Explorer, if I'm not mistaken) ; the limit is much more for POST, and generally depends on the server's configuration.
使用GET,您的用户可以在浏览器中使用“后退”按钮,他们可以为页面添加书签
您可以作为GET传递的参数大小有限制(对于某些版本的Internet Explorer,如果我没有记错的话,则为2KB); POST的限制更多,通常取决于服务器的配置。
Anyway, I don't think we could "live" without GET : think of how many URLs you are using with parameters in the query string, every day -- without GET, all those wouldn't work ;-)
无论如何,我不认为没有GET就可以“活”:想想你每天使用参数在查询字符串中使用了多少个URL - 没有GET,所有这些都不起作用;-)
#6
11
Apart from the length constraints difference in many web browsers, there is also a semantic difference. GETs are supposed to be "safe" in that they are read-only operations that don't change the server state. POSTs will typically change state and will give warnings on resubmission. Search engines' web crawlers may make GETs but should never make POSTs.
除了许多Web浏览器中的长度约束差异之外,还存在语义差异。 GET应该是“安全的”,因为它们是不改变服务器状态的只读操作。 POST通常会更改状态,并会在重新提交时发出警告。搜索引擎的网络抓取工具可以进行GET但不应该进行POST。
Use GET if you want to read data without changing state, and use POST if you want to update state on the server.
如果要在不更改状态的情况下读取数据,请使用GET;如果要更新服务器上的状态,请使用POST。
#7
8
My general rule of thumb is to use Get when you are making requests to the server that aren't going to alter state. Posts are reserved for requests to the server that alter state.
我的一般经验法则是当您向服务器发出不会改变状态的请求时使用Get。帖子保留用于改变状态的服务器的请求。
#8
8
One practical difference is that browsers and webservers have a limit on the number of characters that can exist in a URL. It's different from application to application, but it's certainly possible to hit it if you've got textarea
s in your forms.
一个实际的区别是浏览器和Web服务器对URL中可以存在的字符数有限制。它从应用程序到应用程序有所不同,但如果你的表单中有textareas,它肯定可以点击它。
Another gotcha with GETs - they get indexed by search engines and other automatic systems. Google once had a product that would pre-fetch links on the page you were viewing, so they'd be faster to load if you clicked those links. It caused major havoc on sites that had links like delete.php?id=1
- people lost their entire sites.
另一个与GET相关的问题 - 它们被搜索引擎和其他自动系统索引。谷歌曾经有一款产品可以预览您正在查看的页面上的链接,因此如果您点击这些链接,它们的加载速度会更快。它对像delete.php?id = 1这样的链接的网站造成了严重破坏 - 人们丢失了整个网站。
#9
7
Use GET when you want the URL to reflect the state of the page. This is useful for viewing dynamically generated pages, such as those seen here. A POST should be used in a form to submit data, like when I click the "Post Your Answer" button. It also produces a cleaner URL since it doesn't generate a parameter string after the path.
如果希望URL反映页面状态,请使用GET。这对于查看动态生成的页面非常有用,例如此处显示的页面。应该在表单中使用POST来提交数据,例如当我单击“发布您的答案”按钮时。它还会生成一个更干净的URL,因为它不会在路径后生成参数字符串。
#10
5
Because GETs are purely URLs, they can be cached by the web browser and may be better used for things like consistently generated images. (Set an Expiry time)
因为GET是纯粹的URL,所以它们可以通过Web浏览器进行缓存,并且可以更好地用于诸如一致生成的图像之类的内容。 (设定到期时间)
One example from the gravatar page: http://www.gravatar.com/avatar/4c3be63a4c2f539b013787725dfce802?d=monsterid
来自gravatar页面的一个例子:http://www.gravatar.com/avatar/4c3be63a4c2f539b013787725dfce802?d = bulletterid
GET may yeild marginally better performance, some webservers write POST contents to a temporary file before invoking the handler.
GET可能会稍微提高性能,一些Web服务器在调用处理程序之前将POST内容写入临时文件。
Another thing to consider is the size limit. GETs are capped by the size of the URL, 1024 bytes by the standard, though browsers may support more.
另一件需要考虑的是尺寸限制。 GET受URL的大小限制,标准为1024字节,但浏览器可能支持更多。
Transferring more data than that should use a POST to get better browser compatibility.
传输更多数据应该使用POST来获得更好的浏览器兼容性。
Even less than that limit is a problem, as another poster wrote, anything in the URL could end up in other parts of the brower's UI, like history.
甚至低于这个限制也是一个问题,正如另一张海报写的那样,URL中的任何内容都可能最终出现在浏览器UI的其他部分,如历史。
#11
4
There is nothing you can't do per-se. The point is that you're not supposed to modify the server state on an HTTP GET. HTTP proxies assume that since HTTP GET does not modify the state then whether a user invokes HTTP GET one time or 1000 times makes no difference. Using this information they assume it is safe to return a cached version of the first HTTP GET. If you break the HTTP specification you risk breaking HTTP client and proxies in the wild. Don't do it :)
没有什么是你不能做的。关键是你不应该在HTTP GET上修改服务器状态。 HTTP代理假设由于HTTP GET不会修改状态,因此用户是否调用HTTP GET一次或1000次没有任何区别。使用这些信息,他们认为返回第一个HTTP GET的缓存版本是安全的。如果您违反HTTP规范,则可能会破坏HTTP客户端和代理。不要这样做:)
#12
4
This traverses into the concept of REST and how the web was kinda intended on being used. There is an excellent podcast on Software Engineering radio that gives an in depth talk about the use of Get and Post.
这涉及到REST的概念以及Web如何被用于使用。软件工程广播中有一个很棒的播客,深入讨论了Get和Post的使用。
Get is used to pull data from the server, where an update action shouldn't be needed. The idea being is that you should be able to use the same GET request over and over and have the same information returned. The URL has the get information in the query string, because it was meant to be able to be easily sent to other systems and people like a address on where to find something.
Get用于从服务器提取数据,不需要更新操作。我们的想法是你应该能够反复使用相同的GET请求并返回相同的信息。 URL在查询字符串中包含获取信息,因为它意味着能够轻松地发送到其他系统以及人们喜欢在哪里查找内容的地址。
Post is supposed to be used (at least by the REST architecture which the web is kinda based on) for pushing information to the server/telling the server to perform an action. Examples like: Update this data, Create this record.
应该使用Post(至少通过Web所基于的REST架构)来将信息推送到服务器/告诉服务器执行操作。例如:更新此数据,创建此记录。
#13
4
1.3 Quick Checklist for Choosing HTTP GET
or POST
1.3选择HTTP GET或POST的快速核对表
Use GET if:
The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).
Use POST if:
The interaction is more like an order, or
The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or
The user be held accountable for the results of the interaction.
#14
3
i dont see a problem using get though, i use it for simple things where it makes sense to keep things on the query string.
我没有看到使用get的问题,我将它用于简单的事情,将事情放在查询字符串上是有意义的。
Using it to update state - like a GET of delete.php?id=5
to delete a page - is very risky. People found that out when Google's web accelerator started prefetching URLs on pages - it hit all the 'delete' links and wiped out peoples' data. Same thing can happen with search engine spiders.
使用它来更新状态 - 就像删除页面的删除gt of delete.php?id = 5一样 - 风险很大。人们发现当Google的网络加速器开始在网页上预取URL时,它会点击所有'删除'链接并消灭人们的数据。搜索引擎蜘蛛也会发生同样的事情。
#15
3
POST can move large data while GET cannot.
POST可以移动大数据,而GET则不能。
But generally it's not about a shortcomming of GET, rather a convention if you want your website/webapp to be behaving nicely.
但一般来说,这并不是关于GET的缺点,而是一个惯例,如果你希望你的网站/ webapp表现得很好。
Have a look at http://www.w3.org/2001/tag/doc/whenToUseGet.html
请查看http://www.w3.org/2001/tag/doc/whenToUseGet.html
#16
3
From RFC 2616:
来自RFC 2616:
9.3 GET
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.9.3 GET GET方法意味着检索Request-URI标识的任何信息(以实体的形式)。如果Request-URI引用数据生成过程,则生成的数据应作为响应中的实体而不是过程的源文本返回,除非该文本恰好是过程的输出。
9.5 POST
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:9.5 POST POST方法用于请求源服务器接受请求中包含的实体,作为请求行中Request-URI标识的资源的新下级。 POST旨在允许统一的方法来涵盖以下功能:
- Annotation of existing resources;
现有资源的注释;
- Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
在公告板,新闻组,邮件列表或类似的文章组中发布消息;
- Providing a block of data, such as the result of submitting a form, to a data-handling process;
提供数据块,例如提交表单的结果,数据处理过程;
- Extending a database through an append operation.
通过追加操作扩展数据库。
The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.
POST方法执行的实际功能由服务器确定,通常依赖于Request-URI。发布的实体从属于该URI,其方式与文件从属于包含它的目录相同,新闻文章从属于发布它的新闻组,或者记录从属于数据库。
The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.
POST方法执行的操作可能不会生成可由URI标识的资源。在这种情况下,200(OK)或204(No Content)是适当的响应状态,具体取决于响应是否包括描述结果的实体。
#17
2
I use POST when I don't want people to see the QueryString or when the QueryString gets large. Also, POST is needed for file uploads.
当我不希望人们看到QueryString或者QueryString变大时,我使用POST。此外,文件上传需要POST。
I don't see a problem using GET though, I use it for simple things where it makes sense to keep things on the QueryString.
我没有看到使用GET的问题,我将它用于简单的事情,将事情放在QueryString上是有意义的。
Using GET will allow linking to a particular page possible too where POST would not work.
使用GET将允许在POST不起作用的情况下链接到特定页面。
#18
2
Simple version of POST GET PUT DELETE
简单版本的POST GET PUT DELETE
- use GET - when you want to get any resource like List of data based on any Id or Name
- use POST - when you want to send any data to server. keep in mind POST is heavy weight operation because for updation we should use PUT instead of POST internally POST will create new resource
- use PUT - when you
使用GET - 当您想要获取任何资源,如基于任何Id或名称的数据列表
使用POST - 当您要将任何数据发送到服务器时。请记住POST是重量级操作,因为对于更新,我们应该使用PUT而不是POST内部POST将创建新资源
使用PUT - 当你
#19
1
The original intent was that GET was used for getting data back and POST was to be anything. The rule of thumb that I use is that if I'm sending anything back to the server, I use POST. If I'm just calling an URL to get back data, I use GET.
最初的意图是GET用于获取数据,POST应该是任何东西。我使用的经验法则是,如果我将任何内容发送回服务器,我会使用POST。如果我只是调用URL来获取数据,我使用GET。
#20
1
Read the article about HTTP in the Wikipedia. It will explain what the protocol is and what it does:
阅读*中有关HTTP的文章。它将解释协议是什么以及它的作用:
GET
Requests a representation of the specified resource. Note that GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications. One reason for this is that GET may be used arbitrarily by robots or crawlers, which should not need to consider the side effects that a request should cause.
请求指定资源的表示。请注意,GET不应用于导致副作用的操作,例如使用它来在Web应用程序中执行操作。其中一个原因是机器人或爬虫可以任意使用GET,这不应该考虑请求应该引起的副作用。
and
POST Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both.
POST将要处理的数据(例如,从HTML表单)提交到标识的资源。数据包含在请求正文中。这可能导致创建新资源或更新现有资源或两者。
The W3C has a document named URIs, Addressability, and the use of HTTP GET and POST that explains when to use what. Citing
W3C有一个名为URIs,可寻址性的文档,以及使用HTTP GET和POST来解释何时使用什么。引用
1.3 Quick Checklist for Choosing HTTP GET or POST
1.3选择HTTP GET或POST的快速核对表
- Use GET if:
- The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).
交互更像是一个问题(即,它是一种安全的操作,例如查询,读取操作或查找)。
如果出现以下情况,请使用GET:交互更像是一个问题(即,它是一个安全的操作,如查询,读取操作或查找)。
and
- Use POST if:
- The interaction is more like an order, or
交互更像是一个订单,或者
- The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or o The user be held accountable for the results of the interaction.
交互以用户将感知的方式(例如,对服务的订阅)改变资源的状态,或者o用户对交互的结果负责。
如果出现以下情况,请使用POST:交互更像是一个订单,或者交互以用户可能感知的方式更改资源的状态(例如,订阅服务),或o用户对结果负责互动。
However, before the final decision to use HTTP GET or POST, please also consider considerations for sensitive data and practical considerations.
但是,在最终决定使用HTTP GET或POST之前,还请考虑敏感数据的考虑因素和实际考虑因素。
A practial example would be whenever you submit an HTML form. You specify either post or get for the form action. PHP will populate $_GET and $_POST accordingly.
每当您提交HTML表单时,都会有一个实际的例子。您可以为表单操作指定post或get。 PHP将相应地填充$ _GET和$ _POST。
#21
1
In PHP, POST
data limit is usually set by your php.ini
. GET
is limited by server/browser settings I believe - usually around 255
bytes.
在PHP中,POST数据限制通常由php.ini设置。 GET受到我认为的服务器/浏览器设置的限制 - 通常大约255个字节。
#22
1
From w3schools.com:
What is HTTP?
什么是HTTP?
The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers.
超文本传输协议(HTTP)旨在实现客户端和服务器之间的通信。
HTTP works as a request-response protocol between a client and server.
HTTP用作客户端和服务器之间的请求 - 响应协议。
A web browser may be the client, and an application on a computer that hosts a web site may be the server.
Web浏览器可以是客户端,并且托管网站的计算机上的应用程序可以是服务器。
Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.
示例:客户端(浏览器)向服务器提交HTTP请求;然后服务器向客户端返回响应。响应包含有关请求的状态信息,还可能包含请求的内容。
Two HTTP Request Methods: GET and POST
两种HTTP请求方法:GET和POST
Two commonly used methods for a request-response between a client and server are: GET and POST.
客户端和服务器之间的请求 - 响应的两种常用方法是:GET和POST。
GET – Requests data from a specified resource POST – Submits data to be processed to a specified resource
GET - 从指定资源请求数据POST - 将要处理的数据提交到指定资源
Here we distinguish the major differences:
在这里,我们区分主要差异:
#23
0
Well one major thing is anything you submit over GET
is going to be exposed via the URL. Secondly as Ceejayoz says, there is a limit on characters for a URL.
好吧,一件重要的事情是,您通过GET提交的任何内容都将通过URL公开。其次,正如Ceejayoz所说,URL的字符有限制。
#24
0
Another difference is that POST generally requires two HTTP operations, whereas GET only requires one.
另一个区别是POST通常需要两个HTTP操作,而GET只需要一个。
Edit: I should clarify--for common programming patterns. Generally responding to a POST with a straight up HTML web page is a questionable design for a variety of reasons, one of which is the annoying "you must resubmit this form, do you wish to do so?" on pressing the back button.
编辑:我应该澄清 - 对于常见的编程模式。一般来说,响应具有直接HTML网页的POST是一个有问题的设计,原因有很多,其中一个是烦人的“你必须重新提交这个表单,你希望这样做吗?”按下后退按钮。
#25
0
As answered by others, there's a limit on url size with get, and files can be submitted with post only.
正如其他人所回答的那样,使用get对url大小进行限制,文件只能通过帖子提交。
I'd like to add that one can add things to a database with a get and perform actions with a post. When a script receives a post or a get, it can do whatever the author wants it to do. I believe the lack of understanding comes from the wording the book chose or how you read it.
我想补充一点,可以通过get来执行操作并使用post执行操作。当脚本收到帖子或获取时,它可以做任何作者想要它做的事情。我认为缺乏理解来自于本书选择的措辞或者你如何阅读。
A script author should use posts to change the database and use get only for retrieval of information.
脚本作者应使用帖子来更改数据库,并仅使用get来检索信息。
Scripting languages provided many means with which to access the request. For example, PHP allows the use of $_REQUEST
to retrieve either a post or a get. One should avoid this in favor of the more specific $_GET
or $_POST
.
脚本语言提供了许多访问请求的方法。例如,PHP允许使用$ _REQUEST来检索post或get。应该避免使用更具体的$ _GET或$ _POST。
In web programming, there's a lot more room for interpretation. There's what one should and what one can do, but which one is better is often up for debate. Luckily, in this case, there is no ambiguity. You should use posts to change data, and you should use get to retrieve information.
在网络编程中,有更多的解释空间。人们应该做什么,做什么做什么,但哪一个更好,往往需要辩论。幸运的是,在这种情况下,没有歧义。您应该使用帖子来更改数据,您应该使用get来检索信息。
#26
0
Gorgapor, mod_rewrite
still often utilizes GET
. It just allows to translate a friendlier URL into a URL with a GET
query string.
Gorgapor,mod_rewrite仍经常使用GET。它只允许将友好的URL转换为带有GET查询字符串的URL。
#27
-1
HTTP Post data doesn't have a specified limit on the amount of data, where as different browsers have different limits for GET's. The RFC 2068 states:
HTTP Post数据没有对数据量的指定限制,因为不同的浏览器对GET有不同的限制。 RFC 2068规定:
Servers should be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations may not properly support these lengths
服务器应该谨慎依赖于长度超过255个字节的URI,因为某些较旧的客户端或代理实现可能无法正确支持这些长度
Specifically you should the right HTTP constructs for what they're used for. HTTP GET's shouldn't have side-effects and can be safely refreshed and stored by HTTP Proxies, etc.
具体来说,您应该使用正确的HTTP构造它们用于什么。 HTTP GET不应该有副作用,可以通过HTTP代理等安全地刷新和存储。
HTTP POST's are used when you want to submit data against a url resource.
当您想要针对url资源提交数据时,将使用HTTP POST。
A typical example for using HTTP GET is on a Search, i.e. Search?Query=my+query A typical example for using a HTTP POST is submitting feedback to an online form.
使用HTTP GET的典型示例是搜索,即搜索?查询=我的+查询使用HTTP POST的典型示例是向在线表单提交反馈。
#1
323
Use POST
for destructive actions such as creation (I'm aware of the irony), editing, and deletion, because you can't hit a POST
action in the address bar of your browser. Use GET
when it's safe to allow a person to call an action. So a URL like:
使用POST进行破坏性操作,例如创建(我知道讽刺),编辑和删除,因为您无法在浏览器的地址栏中点击POST操作。如果允许某人呼叫某个动作是安全的,请使用GET。所以像这样的URL:
http://myblog.org/admin/posts/delete/357
Should bring you to a confirmation page, rather than simply deleting the item. It's far easier to avoid accidents this way.
应该带您到确认页面,而不是简单地删除该项目。以这种方式避免事故要容易得多。
POST
is also more secure than GET
, because you aren't sticking information into a URL. And so using GET
as the method
for an HTML form that collects a password or other sensitive information is not the best idea.
POST也比GET更安全,因为您没有将信息粘贴到URL中。因此,使用GET作为收集密码或其他敏感信息的HTML表单的方法并不是最好的主意。
One final note: POST
can transmit a larger amount of information than GET
. 'POST' has no size restrictions for transmitted data, whilst 'GET' is limited to 2048 characters.
最后一点:POST可以传输比GET更多的信息。 'POST'对传输的数据没有大小限制,而'GET'限制为2048个字符。
#2
181
In brief
- Use
GET
forsafe and idempotent
requests - Use
POST
forneither safe nor idempotent
requests
使用GET来获得安全和幂等的请求
使用POST既不是安全请求也不是幂等请求
In details There is a proper place for each. Even if you don't follow RESTful principles, a lot can be gained from learning about REST and how a resource oriented approach works.
详细信息每个都有适当的位置。即使您不遵循RESTful原则,也可以从学习REST以及面向资源的方法如何工作中获得很多。
A RESTful application will
use GETs
for operations which are bothsafe and idempotent
.RESTful应用程序将使用GET进行安全和幂等操作。
A safe
operation is an operation which does not change the data
requested.
安全操作是不改变所请求数据的操作。
An idempotent
operation is one in which the result will be the same
no matter how many times you request it.
幂等操作是指无论您请求多少次,结果都是相同的操作。
It stands to reason that, as GETs are used for safe operations they are automatically also idempotent. Typically a GET is used for retrieving a resource (a question and its associated answers on stack overflow for example) or collection of resources.
按理说,由于GET用于安全操作,它们自动也是幂等的。通常,GET用于检索资源(例如,关于堆栈溢出的问题及其相关答案)或资源集合。
A RESTful app will use
PUTs
for operations which arenot safe but idempotent
.RESTful应用程序将使用PUT进行不安全但幂等的操作。
I know the question was about GET and POST, but I'll return to POST in a second.
我知道问题是关于GET和POST,但我会在一秒钟内回到POST。
Typically a PUT is used for editing a resource (editing a question or an answer on stack overflow for example).
通常,PUT用于编辑资源(例如,编辑有关堆栈溢出的问题或答案)。
A
POST
would be used for any operation which isneither safe or idempotent
.POST将用于任何既不安全也不是幂等的操作。
Typically a POST would be used to create a new resource for example creating a NEW SO question (though in some designs a PUT would be used for this also).
通常,POST将用于创建新资源,例如创建一个新的SO问题(尽管在某些设计中也会使用PUT)。
If you run the POST twice you would end up creating TWO new questions.
如果你运行POST两次,你最终会创建两个新问题。
There's also a DELETE operation, but I'm guessing I can leave that there :)
还有一个DELETE操作,但我猜我可以留下那里:)
Discussion
In practical terms modern web browsers typically only support GET and POST reliably (you can perform all of these operations via javascript calls, but in terms of entering data in forms and pressing submit you've generally got the two options). In a RESTful application the POST will often be overriden to provide the PUT and DELETE calls also.
实际上,现代Web浏览器通常只能可靠地支持GET和POST(您可以通过javascript调用执行所有这些操作,但就在表单中输入数据和按提交而言,您通常有两个选项)。在RESTful应用程序中,POST通常会被覆盖以提供PUT和DELETE调用。
But, even if you are not following RESTful principles, it can be useful to think in terms of using GET for retrieving / viewing information and POST for creating / editing information.
但是,即使您没有遵循RESTful原则,考虑使用GET检索/查看信息和POST来创建/编辑信息也是有用的。
You should never use GET for an operation which alters data. If a search engine crawls a link to your evil op, or the client bookmarks it could spell big trouble.
永远不要将GET用于改变数据的操作。如果搜索引擎抓取指向您的恶意操作的链接,或客户端书签,则可能会遇到大麻烦。
#3
70
Use GET if you don't mind the request being repeated (That is it doesn't change state).
如果您不介意重复请求(即它不会改变状态),请使用GET。
Use POST if the operation does change the system's state.
如果操作确实改变了系统的状态,请使用POST。
#4
63
Short Version
GET: Usually used for submitted search requests, or any request where you want the user to be able to pull up the exact page again.
GET:通常用于提交的搜索请求,或者您希望用户能够再次提取确切页面的任何请求。
Advantages of GET:
GET的优点:
- URLs can be bookmarked safely.
- Pages can be reloaded safely.
可以安全地为URL添加书签。
页面可以安全重新加载。
Disadvantages of GET:
GET的缺点:
- Variables are passed through url as name-value pairs. (Security risk)
- Limited number of variables that can be passed. (Based upon browser. For example, Internet Explorer is limited to 2,048 characters.)
变量作为名称 - 值对传递给url。 (安全风险)
可以传递的变量数量有限。 (基于浏览器。例如,Internet Explorer限制为2,048个字符。)
POST: Used for higher security requests where data may be used to alter a database, or a page that you don't want someone to bookmark.
POST:用于更高安全性请求,其中数据可用于更改数据库,或用于不希望某人加入书签的页面。
Advantages of POST:
POST的优点:
- Name-value pairs are not displayed in url. (Security += 1)
- Unlimited number of name-value pairs can be passed via POST. Reference.
名称 - 值对不会显示在url中。 (安全+ = 1)
可以通过POST传递无限数量的名称 - 值对。参考。
Disadvantages of POST:
POST的缺点:
- Page that used POST data cannot be bookmark. (If you so desired.)
使用POST数据的页面无法添加书签。 (如果你愿意的话。)
Longer Version
Directly from the Hypertext Transfer Protocol -- HTTP/1.1:
直接来自超文本传输协议 - HTTP / 1.1:
9.3 GET
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.
GET方法意味着检索由Request-URI标识的任何信息(以实体的形式)。如果Request-URI引用数据生成过程,则生成的数据应作为响应中的实体而不是过程的源文本返回,除非该文本恰好是过程的输出。
The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.
如果请求消息包括If-Modified-Since,If-Unmodified-Since,If-Match,If-None-Match或If-Range头字段,则GET方法的语义变为“条件GET”。条件GET方法请求仅在条件头字段描述的情况下传送实体。条件GET方法旨在通过允许刷新缓存的实体而不需要多个请求或传输客户端已经拥有的数据来减少不必要的网络使用。
The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.
如果请求消息包括Range头字段,则GET方法的语义变为“部分GET”。部分GET请求仅传输实体的一部分,如第14.35节所述。部分GET方法旨在通过允许完成部分检索的实体而不传输客户端已经拥有的数据来减少不必要的网络使用。
The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in section 13.
当且仅当它满足第13节中描述的HTTP缓存要求时,对GET请求的响应才是可缓存的。
See section 15.1.3 for security considerations when used for forms.
有关用于表单的安全注意事项,请参见第15.1.3节。
9.5 POST
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
POST方法用于请求源服务器接受请求中包含的实体作为Request-URI中Request-URI标识的资源的新下级。 POST旨在允许统一的方法来涵盖以下功能:
Annotation of existing resources;
现有资源的注释;
Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
在公告板,新闻组,邮件列表或类似的文章组中发布消息;
Providing a block of data, such as the result of submitting a form, to a data-handling process;
提供数据块,例如提交表单的结果,数据处理过程;
Extending a database through an append operation.
通过追加操作扩展数据库。
The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.
POST方法执行的实际功能由服务器确定,通常依赖于Request-URI。发布的实体从属于该URI,其方式与文件从属于包含它的目录相同,新闻文章从属于发布它的新闻组,或者记录从属于数据库。
The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.
POST方法执行的操作可能不会生成可由URI标识的资源。在这种情况下,200(OK)或204(No Content)是适当的响应状态,具体取决于响应是否包括描述结果的实体。
#5
27
The first important thing is the meaning of GET versus POST :
第一个重要的是GET与POST的含义:
- GET should be used to... get... some information from the server,
- while POST should be used to send some information to the server.
应该使用GET来...从服务器获取一些信息,
而POST应该用于向服务器发送一些信息。
After that, a couple of things that can be noted :
在那之后,可以注意到以下几点:
- Using GET, your users can use the "back" button in their browser, and they can bookmark pages
- There is a limit in the size of the parameters you can pass as GET (2KB for some versions of Internet Explorer, if I'm not mistaken) ; the limit is much more for POST, and generally depends on the server's configuration.
使用GET,您的用户可以在浏览器中使用“后退”按钮,他们可以为页面添加书签
您可以作为GET传递的参数大小有限制(对于某些版本的Internet Explorer,如果我没有记错的话,则为2KB); POST的限制更多,通常取决于服务器的配置。
Anyway, I don't think we could "live" without GET : think of how many URLs you are using with parameters in the query string, every day -- without GET, all those wouldn't work ;-)
无论如何,我不认为没有GET就可以“活”:想想你每天使用参数在查询字符串中使用了多少个URL - 没有GET,所有这些都不起作用;-)
#6
11
Apart from the length constraints difference in many web browsers, there is also a semantic difference. GETs are supposed to be "safe" in that they are read-only operations that don't change the server state. POSTs will typically change state and will give warnings on resubmission. Search engines' web crawlers may make GETs but should never make POSTs.
除了许多Web浏览器中的长度约束差异之外,还存在语义差异。 GET应该是“安全的”,因为它们是不改变服务器状态的只读操作。 POST通常会更改状态,并会在重新提交时发出警告。搜索引擎的网络抓取工具可以进行GET但不应该进行POST。
Use GET if you want to read data without changing state, and use POST if you want to update state on the server.
如果要在不更改状态的情况下读取数据,请使用GET;如果要更新服务器上的状态,请使用POST。
#7
8
My general rule of thumb is to use Get when you are making requests to the server that aren't going to alter state. Posts are reserved for requests to the server that alter state.
我的一般经验法则是当您向服务器发出不会改变状态的请求时使用Get。帖子保留用于改变状态的服务器的请求。
#8
8
One practical difference is that browsers and webservers have a limit on the number of characters that can exist in a URL. It's different from application to application, but it's certainly possible to hit it if you've got textarea
s in your forms.
一个实际的区别是浏览器和Web服务器对URL中可以存在的字符数有限制。它从应用程序到应用程序有所不同,但如果你的表单中有textareas,它肯定可以点击它。
Another gotcha with GETs - they get indexed by search engines and other automatic systems. Google once had a product that would pre-fetch links on the page you were viewing, so they'd be faster to load if you clicked those links. It caused major havoc on sites that had links like delete.php?id=1
- people lost their entire sites.
另一个与GET相关的问题 - 它们被搜索引擎和其他自动系统索引。谷歌曾经有一款产品可以预览您正在查看的页面上的链接,因此如果您点击这些链接,它们的加载速度会更快。它对像delete.php?id = 1这样的链接的网站造成了严重破坏 - 人们丢失了整个网站。
#9
7
Use GET when you want the URL to reflect the state of the page. This is useful for viewing dynamically generated pages, such as those seen here. A POST should be used in a form to submit data, like when I click the "Post Your Answer" button. It also produces a cleaner URL since it doesn't generate a parameter string after the path.
如果希望URL反映页面状态,请使用GET。这对于查看动态生成的页面非常有用,例如此处显示的页面。应该在表单中使用POST来提交数据,例如当我单击“发布您的答案”按钮时。它还会生成一个更干净的URL,因为它不会在路径后生成参数字符串。
#10
5
Because GETs are purely URLs, they can be cached by the web browser and may be better used for things like consistently generated images. (Set an Expiry time)
因为GET是纯粹的URL,所以它们可以通过Web浏览器进行缓存,并且可以更好地用于诸如一致生成的图像之类的内容。 (设定到期时间)
One example from the gravatar page: http://www.gravatar.com/avatar/4c3be63a4c2f539b013787725dfce802?d=monsterid
来自gravatar页面的一个例子:http://www.gravatar.com/avatar/4c3be63a4c2f539b013787725dfce802?d = bulletterid
GET may yeild marginally better performance, some webservers write POST contents to a temporary file before invoking the handler.
GET可能会稍微提高性能,一些Web服务器在调用处理程序之前将POST内容写入临时文件。
Another thing to consider is the size limit. GETs are capped by the size of the URL, 1024 bytes by the standard, though browsers may support more.
另一件需要考虑的是尺寸限制。 GET受URL的大小限制,标准为1024字节,但浏览器可能支持更多。
Transferring more data than that should use a POST to get better browser compatibility.
传输更多数据应该使用POST来获得更好的浏览器兼容性。
Even less than that limit is a problem, as another poster wrote, anything in the URL could end up in other parts of the brower's UI, like history.
甚至低于这个限制也是一个问题,正如另一张海报写的那样,URL中的任何内容都可能最终出现在浏览器UI的其他部分,如历史。
#11
4
There is nothing you can't do per-se. The point is that you're not supposed to modify the server state on an HTTP GET. HTTP proxies assume that since HTTP GET does not modify the state then whether a user invokes HTTP GET one time or 1000 times makes no difference. Using this information they assume it is safe to return a cached version of the first HTTP GET. If you break the HTTP specification you risk breaking HTTP client and proxies in the wild. Don't do it :)
没有什么是你不能做的。关键是你不应该在HTTP GET上修改服务器状态。 HTTP代理假设由于HTTP GET不会修改状态,因此用户是否调用HTTP GET一次或1000次没有任何区别。使用这些信息,他们认为返回第一个HTTP GET的缓存版本是安全的。如果您违反HTTP规范,则可能会破坏HTTP客户端和代理。不要这样做:)
#12
4
This traverses into the concept of REST and how the web was kinda intended on being used. There is an excellent podcast on Software Engineering radio that gives an in depth talk about the use of Get and Post.
这涉及到REST的概念以及Web如何被用于使用。软件工程广播中有一个很棒的播客,深入讨论了Get和Post的使用。
Get is used to pull data from the server, where an update action shouldn't be needed. The idea being is that you should be able to use the same GET request over and over and have the same information returned. The URL has the get information in the query string, because it was meant to be able to be easily sent to other systems and people like a address on where to find something.
Get用于从服务器提取数据,不需要更新操作。我们的想法是你应该能够反复使用相同的GET请求并返回相同的信息。 URL在查询字符串中包含获取信息,因为它意味着能够轻松地发送到其他系统以及人们喜欢在哪里查找内容的地址。
Post is supposed to be used (at least by the REST architecture which the web is kinda based on) for pushing information to the server/telling the server to perform an action. Examples like: Update this data, Create this record.
应该使用Post(至少通过Web所基于的REST架构)来将信息推送到服务器/告诉服务器执行操作。例如:更新此数据,创建此记录。
#13
4
1.3 Quick Checklist for Choosing HTTP GET
or POST
1.3选择HTTP GET或POST的快速核对表
Use GET if:
The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).
Use POST if:
The interaction is more like an order, or
The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or
The user be held accountable for the results of the interaction.
#14
3
i dont see a problem using get though, i use it for simple things where it makes sense to keep things on the query string.
我没有看到使用get的问题,我将它用于简单的事情,将事情放在查询字符串上是有意义的。
Using it to update state - like a GET of delete.php?id=5
to delete a page - is very risky. People found that out when Google's web accelerator started prefetching URLs on pages - it hit all the 'delete' links and wiped out peoples' data. Same thing can happen with search engine spiders.
使用它来更新状态 - 就像删除页面的删除gt of delete.php?id = 5一样 - 风险很大。人们发现当Google的网络加速器开始在网页上预取URL时,它会点击所有'删除'链接并消灭人们的数据。搜索引擎蜘蛛也会发生同样的事情。
#15
3
POST can move large data while GET cannot.
POST可以移动大数据,而GET则不能。
But generally it's not about a shortcomming of GET, rather a convention if you want your website/webapp to be behaving nicely.
但一般来说,这并不是关于GET的缺点,而是一个惯例,如果你希望你的网站/ webapp表现得很好。
Have a look at http://www.w3.org/2001/tag/doc/whenToUseGet.html
请查看http://www.w3.org/2001/tag/doc/whenToUseGet.html
#16
3
From RFC 2616:
来自RFC 2616:
9.3 GET
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.9.3 GET GET方法意味着检索Request-URI标识的任何信息(以实体的形式)。如果Request-URI引用数据生成过程,则生成的数据应作为响应中的实体而不是过程的源文本返回,除非该文本恰好是过程的输出。
9.5 POST
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:9.5 POST POST方法用于请求源服务器接受请求中包含的实体,作为请求行中Request-URI标识的资源的新下级。 POST旨在允许统一的方法来涵盖以下功能:
- Annotation of existing resources;
现有资源的注释;
- Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
在公告板,新闻组,邮件列表或类似的文章组中发布消息;
- Providing a block of data, such as the result of submitting a form, to a data-handling process;
提供数据块,例如提交表单的结果,数据处理过程;
- Extending a database through an append operation.
通过追加操作扩展数据库。
The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.
POST方法执行的实际功能由服务器确定,通常依赖于Request-URI。发布的实体从属于该URI,其方式与文件从属于包含它的目录相同,新闻文章从属于发布它的新闻组,或者记录从属于数据库。
The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.
POST方法执行的操作可能不会生成可由URI标识的资源。在这种情况下,200(OK)或204(No Content)是适当的响应状态,具体取决于响应是否包括描述结果的实体。
#17
2
I use POST when I don't want people to see the QueryString or when the QueryString gets large. Also, POST is needed for file uploads.
当我不希望人们看到QueryString或者QueryString变大时,我使用POST。此外,文件上传需要POST。
I don't see a problem using GET though, I use it for simple things where it makes sense to keep things on the QueryString.
我没有看到使用GET的问题,我将它用于简单的事情,将事情放在QueryString上是有意义的。
Using GET will allow linking to a particular page possible too where POST would not work.
使用GET将允许在POST不起作用的情况下链接到特定页面。
#18
2
Simple version of POST GET PUT DELETE
简单版本的POST GET PUT DELETE
- use GET - when you want to get any resource like List of data based on any Id or Name
- use POST - when you want to send any data to server. keep in mind POST is heavy weight operation because for updation we should use PUT instead of POST internally POST will create new resource
- use PUT - when you
使用GET - 当您想要获取任何资源,如基于任何Id或名称的数据列表
使用POST - 当您要将任何数据发送到服务器时。请记住POST是重量级操作,因为对于更新,我们应该使用PUT而不是POST内部POST将创建新资源
使用PUT - 当你
#19
1
The original intent was that GET was used for getting data back and POST was to be anything. The rule of thumb that I use is that if I'm sending anything back to the server, I use POST. If I'm just calling an URL to get back data, I use GET.
最初的意图是GET用于获取数据,POST应该是任何东西。我使用的经验法则是,如果我将任何内容发送回服务器,我会使用POST。如果我只是调用URL来获取数据,我使用GET。
#20
1
Read the article about HTTP in the Wikipedia. It will explain what the protocol is and what it does:
阅读*中有关HTTP的文章。它将解释协议是什么以及它的作用:
GET
Requests a representation of the specified resource. Note that GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications. One reason for this is that GET may be used arbitrarily by robots or crawlers, which should not need to consider the side effects that a request should cause.
请求指定资源的表示。请注意,GET不应用于导致副作用的操作,例如使用它来在Web应用程序中执行操作。其中一个原因是机器人或爬虫可以任意使用GET,这不应该考虑请求应该引起的副作用。
and
POST Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both.
POST将要处理的数据(例如,从HTML表单)提交到标识的资源。数据包含在请求正文中。这可能导致创建新资源或更新现有资源或两者。
The W3C has a document named URIs, Addressability, and the use of HTTP GET and POST that explains when to use what. Citing
W3C有一个名为URIs,可寻址性的文档,以及使用HTTP GET和POST来解释何时使用什么。引用
1.3 Quick Checklist for Choosing HTTP GET or POST
1.3选择HTTP GET或POST的快速核对表
- Use GET if:
- The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).
交互更像是一个问题(即,它是一种安全的操作,例如查询,读取操作或查找)。
如果出现以下情况,请使用GET:交互更像是一个问题(即,它是一个安全的操作,如查询,读取操作或查找)。
and
- Use POST if:
- The interaction is more like an order, or
交互更像是一个订单,或者
- The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or o The user be held accountable for the results of the interaction.
交互以用户将感知的方式(例如,对服务的订阅)改变资源的状态,或者o用户对交互的结果负责。
如果出现以下情况,请使用POST:交互更像是一个订单,或者交互以用户可能感知的方式更改资源的状态(例如,订阅服务),或o用户对结果负责互动。
However, before the final decision to use HTTP GET or POST, please also consider considerations for sensitive data and practical considerations.
但是,在最终决定使用HTTP GET或POST之前,还请考虑敏感数据的考虑因素和实际考虑因素。
A practial example would be whenever you submit an HTML form. You specify either post or get for the form action. PHP will populate $_GET and $_POST accordingly.
每当您提交HTML表单时,都会有一个实际的例子。您可以为表单操作指定post或get。 PHP将相应地填充$ _GET和$ _POST。
#21
1
In PHP, POST
data limit is usually set by your php.ini
. GET
is limited by server/browser settings I believe - usually around 255
bytes.
在PHP中,POST数据限制通常由php.ini设置。 GET受到我认为的服务器/浏览器设置的限制 - 通常大约255个字节。
#22
1
From w3schools.com:
What is HTTP?
什么是HTTP?
The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers.
超文本传输协议(HTTP)旨在实现客户端和服务器之间的通信。
HTTP works as a request-response protocol between a client and server.
HTTP用作客户端和服务器之间的请求 - 响应协议。
A web browser may be the client, and an application on a computer that hosts a web site may be the server.
Web浏览器可以是客户端,并且托管网站的计算机上的应用程序可以是服务器。
Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.
示例:客户端(浏览器)向服务器提交HTTP请求;然后服务器向客户端返回响应。响应包含有关请求的状态信息,还可能包含请求的内容。
Two HTTP Request Methods: GET and POST
两种HTTP请求方法:GET和POST
Two commonly used methods for a request-response between a client and server are: GET and POST.
客户端和服务器之间的请求 - 响应的两种常用方法是:GET和POST。
GET – Requests data from a specified resource POST – Submits data to be processed to a specified resource
GET - 从指定资源请求数据POST - 将要处理的数据提交到指定资源
Here we distinguish the major differences:
在这里,我们区分主要差异:
#23
0
Well one major thing is anything you submit over GET
is going to be exposed via the URL. Secondly as Ceejayoz says, there is a limit on characters for a URL.
好吧,一件重要的事情是,您通过GET提交的任何内容都将通过URL公开。其次,正如Ceejayoz所说,URL的字符有限制。
#24
0
Another difference is that POST generally requires two HTTP operations, whereas GET only requires one.
另一个区别是POST通常需要两个HTTP操作,而GET只需要一个。
Edit: I should clarify--for common programming patterns. Generally responding to a POST with a straight up HTML web page is a questionable design for a variety of reasons, one of which is the annoying "you must resubmit this form, do you wish to do so?" on pressing the back button.
编辑:我应该澄清 - 对于常见的编程模式。一般来说,响应具有直接HTML网页的POST是一个有问题的设计,原因有很多,其中一个是烦人的“你必须重新提交这个表单,你希望这样做吗?”按下后退按钮。
#25
0
As answered by others, there's a limit on url size with get, and files can be submitted with post only.
正如其他人所回答的那样,使用get对url大小进行限制,文件只能通过帖子提交。
I'd like to add that one can add things to a database with a get and perform actions with a post. When a script receives a post or a get, it can do whatever the author wants it to do. I believe the lack of understanding comes from the wording the book chose or how you read it.
我想补充一点,可以通过get来执行操作并使用post执行操作。当脚本收到帖子或获取时,它可以做任何作者想要它做的事情。我认为缺乏理解来自于本书选择的措辞或者你如何阅读。
A script author should use posts to change the database and use get only for retrieval of information.
脚本作者应使用帖子来更改数据库,并仅使用get来检索信息。
Scripting languages provided many means with which to access the request. For example, PHP allows the use of $_REQUEST
to retrieve either a post or a get. One should avoid this in favor of the more specific $_GET
or $_POST
.
脚本语言提供了许多访问请求的方法。例如,PHP允许使用$ _REQUEST来检索post或get。应该避免使用更具体的$ _GET或$ _POST。
In web programming, there's a lot more room for interpretation. There's what one should and what one can do, but which one is better is often up for debate. Luckily, in this case, there is no ambiguity. You should use posts to change data, and you should use get to retrieve information.
在网络编程中,有更多的解释空间。人们应该做什么,做什么做什么,但哪一个更好,往往需要辩论。幸运的是,在这种情况下,没有歧义。您应该使用帖子来更改数据,您应该使用get来检索信息。
#26
0
Gorgapor, mod_rewrite
still often utilizes GET
. It just allows to translate a friendlier URL into a URL with a GET
query string.
Gorgapor,mod_rewrite仍经常使用GET。它只允许将友好的URL转换为带有GET查询字符串的URL。
#27
-1
HTTP Post data doesn't have a specified limit on the amount of data, where as different browsers have different limits for GET's. The RFC 2068 states:
HTTP Post数据没有对数据量的指定限制,因为不同的浏览器对GET有不同的限制。 RFC 2068规定:
Servers should be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations may not properly support these lengths
服务器应该谨慎依赖于长度超过255个字节的URI,因为某些较旧的客户端或代理实现可能无法正确支持这些长度
Specifically you should the right HTTP constructs for what they're used for. HTTP GET's shouldn't have side-effects and can be safely refreshed and stored by HTTP Proxies, etc.
具体来说,您应该使用正确的HTTP构造它们用于什么。 HTTP GET不应该有副作用,可以通过HTTP代理等安全地刷新和存储。
HTTP POST's are used when you want to submit data against a url resource.
当您想要针对url资源提交数据时,将使用HTTP POST。
A typical example for using HTTP GET is on a Search, i.e. Search?Query=my+query A typical example for using a HTTP POST is submitting feedback to an online form.
使用HTTP GET的典型示例是搜索,即搜索?查询=我的+查询使用HTTP POST的典型示例是向在线表单提交反馈。