问题描述
对于 HTML 表单.我很困惑,我正在尝试设置 enctype='application/octet-stream' 但服务器收到带有 content-type ='application/x-www-form-urlencoded'(默认值)的请求.
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).
推荐答案
enctype
属性指定内容类型(在 HTTP 术语中,如 Content-Type
标头所示) 浏览器向服务器提交表单数据时使用.
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.
然而,规范仅定义此上下文中的两种内容类型,application/x-www-form-urlencoded
(默认)和 multipart/form-data
,并添加:其他内容类型的行为未指明."在实践中发生的情况是浏览器使用默认值默默地忽略具有其他值的 enctype
属性.如果您例如,您可以看到这一点在 Firebug 中检查文档:检查 form
元素,DOM 窗格包含属性 enctype
——具有默认值.Web 浏览器中对标记中的错误保持沉默是很常见的.
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.
application/octet-stream
类型在这种情况下不会很有用,因为如果浏览器发送这样的信息,它会有效地说这是未知的二进制数据块(或未指定)结构".
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".
这篇关于content-type 和 enctype 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!