Html 默认的表单 HTTP 方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2314401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:17:11  来源:igfitidea点击:

What is the default form HTTP method?

htmlforms

提问by David

When an HTML form is submitted without specifying a method, what is the default HTTP method used? GET or POST?

提交 HTML 表单而不指定方法时,使用的默认 HTTP 方法是什么?获取还是发布?

Has this behaviour ever changed between HTML standards?

这种行为是否在 HTML 标准之间发生过变化?

Please cite a W3C standard document if possible.

如果可能,请引用 W3C 标准文档。

回答by Drew Wills

It's GET.

它是获取。

Take a look W3C Superceded Recommendation 17.3 The FORM element.

看看W3C 取代的建议 17.3 FORM 元素

Excerpt:

摘抄:

<!ATTLIST FORM
  %attrs;                              -- %coreattrs, %i18n, %events --
  action      %URI;          #REQUIRED -- server-side form handler --
  method      (GET|POST)     GET       -- HTTP method used to submit the form--
  enctype     %ContentType;  "application/x-www-form-urlencoded"
  accept      %ContentTypes; #IMPLIED  -- list of MIME types for file upload --
  name        CDATA          #IMPLIED  -- name of form for scripting --
  onsubmit    %Script;       #IMPLIED  -- the form was submitted --
  onreset     %Script;       #IMPLIED  -- the form was reset --
  accept-charset %Charsets;  #IMPLIED  -- list of supported charsets --
  >

Good read

好读

Methods GET and POST in HTML forms - what's the difference?

HTML 表单中的 GET 和 POST 方法 - 有什么区别?

回答by Jon Seigel

Hereis the W3C reference, which says GET is the default.

是 W3C 参考,它说 GET 是默认值。

回答by Roger Willcocks

If not specified, the default is GET. I see no indication that this behaviour has ever been different. And it makes sense the GET is the default, as it specifies that method should be used for actions without side effects.

如果未指定,则默认为 GET。我没有看到任何迹象表明这种行为曾经有所不同。并且 GET 是默认值是有道理的,因为它指定该方法应该用于没有副作用的操作。

http://www.faqs.org/faqs/www/cgi-faq/section-37.html

http://www.faqs.org/faqs/www/cgi-faq/section-37.html

Citations from http://www.w3.org/TR/html401/interact/forms.html#h-17.3:

引自http://www.w3.org/TR/html401/interact/forms.html#h-17.3

method = get|post[CI]
This attribute specifies which HTTP method will be used to submit the form data set. Possible (case-insensitive) values are "get" (the default) and "post". See the section on form submission for usage information.

17.13.1 Form submission method
The method attribute of the FORMelement specifies the HTTP method used to send the form to the processing agent. This attribute may take two values:

  • get: With the HTTP "get" method, the form data set is appended to the URI specified by the action attribute (with a question-mark ("?") as separator) and this new URI is sent to the processing agent.

  • post: With the HTTP "post" method, the form data set is included in the body of the form and sent to the processing agent.

The "get" method should be used when the form is idempotent (i.e., causes no side-effects). Many database searches have no visible side-effects and make ideal applications for the "get" method.

method = get|post[CI]
此属性指定将使用哪种 HTTP 方法提交表单数据集。可能的(不区分大小写)值为“ get”(默认值)和“ post”。有关使用信息,请参阅表单提交部分。

17.13.1 表单提交方法元素
的method 属性FORM指定用于将表单发送到处理代理的HTTP 方法。这个属性可能有两个值:

  • get:使用 HTTP 的“get”方法,表单数据集被附加到由 action 属性指定的 URI(使用问号 (“?”) 作为分隔符),并将这个新的 URI 发送到处理代理。

  • post:使用HTTP“post”方法,将表单数据集包含在表单正文中并发送到处理代理。

当表单是幂等的(即不会产生副作用)时,应该使用“get”方法。许多数据库搜索没有明显的副作用,是“get”方法的理想应用。

回答by ghoppe

According to The W3C standardyou're asking for, the default should be GET.

根据您要求的 W3C 标准,默认值应为 GET。

回答by ghoppe

(fuller answer, also about action and enctype)

(更完整的答案,也关于动作和编码)

The default 'method', 'action' and 'enctype' of an HTML form,if they are not specified,
are GET, current URL and application/x-www-form-urlencodedrespectively.
(I.e., by default, a form requests current page with the inputted parameters.)

HTML 表单的默认 'method'、'action' 和 'enctype'(如果未指定)
分别是 GET、当前 URL 和application/x-www-form-urlencoded
(即,默认情况下,表单使用输入的参数请求当前页面。)

This behaviour has never changed, except 'action' (in HTML 4 it was required). Citations:

这种行为从未改变,除了“动作”(在 HTML 4 中是必需的)。引文:

method: "The missing value defaultfor the method attribute is... the GET state."
action:

方法:“方法属性的缺失值默认是...... GET 状态。”
行动:

The action of an element is the value of the element's formaction attribute, if the element is a Submit Button and has such an attribute, or the value of its form owner's action attribute, if it has one, or else the empty string. <...> If actionis the empty string, let actionbe the document's URL of the form document.

元素的 action 是元素的 formaction 属性的值,如果元素是提交按钮并具有这样的属性,或者其表单所有者的 action 属性的值(如果有),否则为空字符串。<...> 如果action是空字符串,让action是表单文档的文档 URL。

enctype: "The missing value defaultfor the enctype attribute is... the application/x-www-form-urlencodedstate."

enctype:“ enctype 属性的缺失值默认是……application/x-www-form-urlencoded状态。”

method: "Possible (case-insensitive) values are 'get' (the default) and 'post'."
action: no default, DTD requires it
enctype: "The default value for this attribute is 'application/x-www-form-urlencoded'."

方法:“可能的(不区分大小写)值为‘get’(默认值)和‘post’。”
操作:无默认值,DTD 要求它
enctype:“此属性的默认值是 'application/x-www-form-urlencoded'。”

<!ATTLIST FORM
  %attrs;                              -- %coreattrs, %i18n, %events --
  action      %URI;          #REQUIRED -- server-side form handler --
  method      (GET|POST)     GET       -- HTTP method used to submit the form--
  enctype     %ContentType;  "application/x-www-form-urlencoded"

method: "It can be either GET or POST, and defaults to GET."
action: no explicit sentence, only in DTD
enctype: "It defaults to application/x-www-form-urlencoded."

方法:“它可以是 GET 或 POST,默认为 GET。”
动作:没有明确的句子,只有在 DTD
enctype 中:“它默认为application/x-www-form-urlencoded。”

<!ATTLIST FORM
        action %URL #IMPLIED  -- server-side form handler --
        method (%HTTP-Method) GET -- see HTTP specification --
        enctype %Content-Type; "application/x-www-form-urlencoded"

method: no explicit sentence, only in DTD
action: "The action URI of a form defaults to the base URI of the document"
enctype: "The default encoding for all forms is `application/x-www-form-urlencoded'."

方法:没有明确的句子,仅在 DTD
action: "表单的动作 URI 默认为文档的基本 URI"
enctype: "所有表单的默认编码是`application/x-www-form-urlencoded'。"

<!ATTLIST FORM
        ACTION CDATA #IMPLIED
        METHOD (%HTTP-Method) GET
        ENCTYPE %Content-Type; "application/x-www-form-urlencoded"