据我所知,有三种类型:

不要使用GET和POST 不要使用POST而使用GET 你用哪一个都不重要。

我对这三种情况的假设正确吗?如果有,每个案例都有哪些例子?


当前回答

我的一般经验法则是,当您向服务器发出不打算改变状态的请求时使用Get。post是为更改状态的服务器请求保留的。

其他回答

重要的一点是,你通过GET提交的任何东西都会通过URL被暴露。其次,正如Ceejayoz所说,URL的字符数量是有限制的。

1.3 HTTP GET / POST选择快速检查

在以下情况下使用GET:

    The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup).

在以下情况下使用POST:

    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.

源。

最初的目的是GET用于获取数据,而POST用于任何用途。我使用的经验法则是,如果我要向服务器发送任何东西,我就使用POST。如果我只是调用一个URL来获取数据,我会使用get。

从w3schools.com:

What is HTTP? The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and server. A web browser may be the client, and an application on a computer that hosts a web site may be the server. 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. Two HTTP Request Methods: GET and POST Two commonly used methods for a request-response between a client and server are: GET and POST. GET – Requests data from a specified resource POST – Submits data to be processed to a specified resource

在这里我们区分主要的区别:

当我不希望人们看到QueryString或当QueryString变大时,我使用POST。另外,文件上传需要POST。

不过,我不认为使用GET有问题,我将它用于简单的事情,其中将内容保留在QueryString上是有意义的。

使用GET将允许链接到POST无法工作的特定页面。