What is the default form HTTP method?

前端 未结 5 2104
悲&欢浪女
悲&欢浪女 2020-11-22 03:01

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

Has this behaviour ever changed between HTML standard

相关标签:
5条回答
  • 2020-11-22 03:33

    It's GET.

    Take a look W3C Superceded Recommendation 17.3 The FORM element.

    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?

    0 讨论(0)
  • 2020-11-22 03:42

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

    0 讨论(0)
  • 2020-11-22 03:46

    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.

    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:

    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.

    0 讨论(0)
  • 2020-11-22 03:49

    (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-urlencoded respectively.
    (I.e., by default, a form requests current page with the inputted parameters.)

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

    • 5 and subsequent, W3C TR

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

    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: "The missing value default for the enctype attribute is... the application/x-www-form-urlencoded state."

    • 4.0, W3C TR; 4.01, W3C TR

    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'."

    <!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

    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."

    <!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.0, RFC

    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'."

    <!ATTLIST FORM
            ACTION CDATA #IMPLIED
            METHOD (%HTTP-Method) GET
            ENCTYPE %Content-Type; "application/x-www-form-urlencoded"
    
    0 讨论(0)
  • 2020-11-22 03:53

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

    0 讨论(0)
提交回复
热议问题