html - 了解 http 请求和响应中的内容类型

标签 html http content-type

你好有人能解释一下你是如何设置type的吗?对于 requestresponse 的类型给出 html元素 ?

示例:

如果我想发送 form发送一些 files和一个 POCO并收到 stream我会用 type=multipart/form-data ;会 type在这种情况下,请参阅 request还是预期的响应?

<form type="multipart/form-data"><input type="file"></form>

在本例中为 type明确指的是请求。但这意味着 server处理请求的必须设置 response.typeapplication/octet-stream .

所以根据这个原因,我认为你在 form 中设置的内容是 request类型。

但是然后我无法理解这个矛盾:

<a class="button" type="application/octet-stream"  href="http://localhost:5300/get" download>Click here for dld</a>

在我没有设置 type 之前我无法下载文件response 在这里。我尝试在服务器中设置响应类型,但它没有用。所以在这种情况下,这里的 type 指的是 response而不是 request .

有人可以解释一下吗?是否有 html 的列表?上的元素 他们指的是什么 type ? (request 或预期的 response 的类型)?

PS
长话短说:为什么 form引用request通过 typea指的是response . 当他想发送内容类型为 A 的请求时,怎么可能有原因呢?他的回复是类型 B .

最佳答案

But then it means that the server that processes the request has to set the response.type to application/octet-stream.

没有。服务器可以响应任何类型的内容。

application/octet-stream是一个毫无意义的“这是一个字节流”。通常,您会想要描述响应的实际内容类型的内容。

Can someone please shed some light?

type <a> 上的属性元素指的是预期 响应类型。这允许机器人在期望得到它无法理解的响应时避免点击链接。

由于链接触发了GET请求,所以没有请求体来描述anyway的类型。

Is there a list with the html elements on what they refer by type ?

HTML 规范描述了它出现的每个元素的类型属性。例如script链接到 this type .


How can one reason when he wants to send a request whose content is type A and his response is type B

您几乎从不需要告诉客户期望的类型,所以不用。只有在构建带正文的 HTTP 请求时才需要担心它。

关于html - 了解 http 请求和响应中的内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54691534/

相关文章:

node.js - 将 request.post 的内容类型 header 设置为 json

java - 尝试使用 MIME 发送 "alternative"但它也出现在有能力的邮件客户端中

html - CSS 无法让悬停状态在简单的 div 上运行

javascript - 在背景音乐中添加两秒延迟

html - 带有 flexbox 和静态宽度的 CSS 侧边栏

node.js - 在 Erlang 中反向代理/转发 HTTP 请求

java - 如何在服务器端为端口编写重试策略以监听客户端请求?

PHP 500 内部错误没有得到解决

java - 接口(interface)/枚举列出标准 mime 类型常量

php - 将数据从html文件发送到php并存储在数据库中