什么是 HTTP“方法”?资本化最佳实践?
我见过 HTTP 方法全部大写和小写字母。例如,您是否有任何理由想要在表单元素的 method 属性中编写 POST
而不是 post
?
某些浏览器对大写的 POST
和 GET
的处理方式是否与小写的 post
和 get
不同?
I have seen HTTP methods written in all caps and in all lowercase letters. Is there any reason why you would want to write POST
rather than post
in the method attribute of a form element, for example?
Do some browsers handle capitalized POST
and GET
differently than lowercase post
and get
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HTML5 规范要求使用“get”或“post”。
The HTML5 spec requires to use "get" or "post".
简短回答:最好在
长答案:这稍微取决于 HTML 版本:
HTML5:html5 生活标准规定小写
get
映射到 HTTP 方法 GET,小写post 映射到 HTTP 方法 POST [1]。然而,截至今天,枚举属性匹配不区分大小写 [2]。所以理论上你可以使用任何外壳。我很确定几年前情况有所不同,但这就是生活水平的本质。 HTML5 标准中的示例使用小写。因此,如果您遵循 HTML5 标准,我建议您使用小写,尽管这并不重要。
XHTML:使用小写。 xhtml-strict 和 xhtml-transitional 的 DTD 只定义了小写的
get
和post
[3, 4]。在这里它甚至更重要,因为使用大写会产生无效的XHTML文档,在实践中可能会触发丑陋的浏览器错误(取决于DTD、浏览器和http内容类型)。HTML 4:如今,使用大写是常见的做法,但小写在实践中也很有效。这只是我的个人经验,我不会查找 HTML 4 标准,因为它现在看起来无关紧要(而且没有人严格遵循它)。
[1] https://www.w3.org/TR /html5/forms.html#attr-fs-method
[2] https://html.spec.whatwg.org/multipage/common- microsyntaxes.html#enumerated-attribute
[3] https://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd 第 695 行
[4] https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd第888行
Short answer: Best use lowercase in
method
attributes of<form>
tags.Long answer: It slightly depends on the HTML version:
HTML5: The html5 living standard states that lowercase
get
maps to the HTTP method GET and that lowercasepost
maps to HTTP method POST [1]. However as of today, enumerated attributes match case-insensitive [2]. So you could in theory use any casing. I am pretty sure this was different a couple of years a ago, but that's the nature of a living standard. The examples in the HTML5 standard use lowercase. So, if you follow HTML5 standard, I would recommend to use lowercase, even though it does not really matter.XHTML: Use lowercase. The DTD of xhtml-strict and xhtml-transitional only define lowercase
get
andpost
[3, 4]. Here its is even more important, as using uppercase will produce an invalid XHTML document that can trigger ugly browser errors in practice (depends on DTD, browser and http content-type).HTML 4: In these days, it was common practice to use uppercase, but lowercase also worked well in practice. This is just my personal experience, I am not going to look up the HTML 4 standard as it seems irrelevant nowadays (and nobody ever followed it strictly anyways).
[1] https://www.w3.org/TR/html5/forms.html#attr-fs-method
[2] https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute
[3] https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd line 695
[4] https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd line 888
无论您在表单的方法声明中使用 POST 还是 post,您的网站都会正常工作。它与您选择的文档类型有更多关系。如果您使用 XHTML,则所有内容都必须小写。如果您不这样做(例如使用 HTML5),也没关系,如果您愿意,甚至可以使用 PoSt。我个人仍然会选择小写变体,但选择是你的。无论您选择什么,重要的是......在页面的其余部分坚持使用它。
Your site will work fine whether you use POST or post in your form's method declaration. It has more to do with the doctype you choose. If you use XHTML, everything must be lowercase. If you do not (and use HTML5 for example) it does not matter and can even be PoSt if you like. I personally still would go for the lowercase variant but the choise is yours. Whatever you choose, the important thing is...stick with it in the rest of your page.