内容类型和enctype之间有什么区别 [英] What's the difference between content-type and enctype
问题描述
对于HTML表单。我很困惑,我试图设置enctype ='application / octet-stream',但服务器收到content-type ='application / x-www-form-urlencoded'(默认值)的请求。 enctype
属性指定内容类型(以HTTP术语,如 Content-Type
标题所示),但是它在向服务器提交表单数据时使用。
然而, ,规范仅定义了两种内容类型这个上下文中, application / x-www-form-urlencoded
(默认)和 multipart / form-data
,以及补充道:其他内容类型的行为是未指定的。实践中发生的情况是,浏览器使用默认值默默地忽略 enctype
属性与其他值。如果你愿意,你可以看到这个检查Firebug中的文档:检查表单
元素,DOM窗格包含属性 enctype
- 使用默认值。
类型 application / octet-stream
会在Web浏览器中常见,在这种情况下不是非常有用,因为如果浏览器发送了这样的信息,那么它将会有效地说这是一个未知(或未指定)结构的二进制数据的集合。
For HTML forms. I am confused, I'm trying to set enctype='application/octet-stream' but the server receives the request with content-type ='application/x-www-form-urlencoded' (the default value).
The enctype
attribute specifies the content type (in HTTP terms, as indicated in Content-Type
header) used by the browser when it submits the form data to server.
However, the spec defines only two content types in this context, application/x-www-form-urlencoded
(the default) and multipart/form-data
, and adds: "Behavior for other content types is unspecified." What happens in practice is that browsers silently ignore enctype
attributes with other values, using the default. You can see this if you e.g. inspect the document in Firebug: inspecting the form
element, the DOM pane contains the property enctype
—with the default value. It is common in web browsers to be silent about errors in markup.
The type application/octet-stream
would not be very useful in this context, since if the browser sent such information, it would be effectively saying "this is lump of binary data of unknown (or unspecified) structure".
这篇关于内容类型和enctype之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!