关于html:HTTP方法的默认形式是什么?

What is the default form HTTP method?

当提交HTML表单而不指定方法时,使用的默认HTTP方法是什么?得到还是邮寄?

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

如有可能,请引用W3C标准文件。


得到了。

看看这里。

Excerpt:

1
2
3
4
5
6
7
8
9
10
11
<!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 --
  >

好读

方法在HTML表单中获取和发布-有什么区别?


这里是W3C引用,它说get是默认值。


如果未指定,则默认值为get。我看不出有任何迹象表明这种行为有任何不同。而且,GET是默认的,因为它指定应该将方法用于没有副作用的操作。

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

引自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 FORM element 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.


根据您要求的W3C标准,缺省值应该是get。


(更完整的答案,同样是关于动作和ENCTYPE)

HTML表单的默认"method"、"action"和"enctype"(如果未指定)是分别为get、current url和application/x-www-form-urlencoded(即默认情况下,表单使用输入的参数请求当前页面。)除了"action"(在HTML 4中是必需的)之外,此行为从未改变。引文:

  • 5及以后,W3C TR

方法:"方法属性缺少的默认值是…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 action is the empty string, let action be the document’s URL of the form document.

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

  • 4.0,W3C TR;4.01,W3C TR

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

1
2
3
4
5
<!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"
  • 3.2,W3C-TR

方法:"它可以是get或post,默认为get。"行动:没有明确的句子,只有在DTD中enctype:"默认为application/x-www-form-urlencoded。"

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

方法:无显式语句,只在DTD中使用action:"表单的action uri默认为文档的基uri"enctype:"所有表单的默认编码是'application/x-www-form-urlencoded'。

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