内容范围和范围标头之间的区别?

发布于 2024-07-16 13:36:11 字数 178 浏览 5 评论 0原文

HTTP 标头 Content-RangeRange 之间有什么区别? 每种应该什么时候使用?

我正在尝试从特定字节偏移量流式传输音频文件。 我应该使用 Content-Range 还是 Range 标头?

What is the difference between HTTP headers Content-Range and Range? When should each be used?

I am trying to stream an audio file from a particular byte offset. Should I use Content-Range or Range header?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2024-07-23 13:36:11

事实上,接受的答案并不完整。 Content-Range 不仅仅用于响应。 提供实体机构的请求也是合法的。

例如,HTTP PUT 提供实体主体,它可能仅提供实体的一部分。 因此,PUT 请求可以包括 Content-Range 标头,向服务器指示部分实体主体应在何处合并到实体中。

例如,我们首先使用 HTTP 创建文件,然后附加到文件:

请求 1:

PUT /file HTTP/1.1
Host: server
Content-Length: 1

a

请求 2:

PUT /file HTTP/1.1
Host: server
Content-Range: bytes 1-2/*
Content-Length: 1

a

如何,让我们看看文件的内容...

请求 3:

GET /file HTTP/1.1
Host: server

HTTP/1.1 200 OK
Content-Length: 2

aa

这允许通过 HTTP 进行随机文件访问,包括读取和写入。 我只是想澄清一下,因为我正在研究在我正在开发的 WebDAV 客户端中使用 Content-Range,所以也许这个扩展的信息对其他人有用。

Actually, the accepted answer is not complete. Content-Range is not only used in responses. It is also legal in requests that provide an entity body.

For example, an HTTP PUT provides an entity body, it might provide only a portion of an entity. Thus the PUT request can include a Content-Range header indicating to the server where the partial entity body should be merged into the entity.

For example, let's first create and then append to a file using HTTP:

Request 1:

PUT /file HTTP/1.1
Host: server
Content-Length: 1

a

Request 2:

PUT /file HTTP/1.1
Host: server
Content-Range: bytes 1-2/*
Content-Length: 1

a

How, let's see the file's contents...

Request 3:

GET /file HTTP/1.1
Host: server

HTTP/1.1 200 OK
Content-Length: 2

aa

This allows random file access, both READING and WRITING over HTTP. I just wanted to clarify, as I was researching the use of Content-Range in a WebDAV client I am developing, so perhaps this expanded information will prove useful to somebody else.

懷念過去 2024-07-23 13:36:11

Range 用于请求中,以请求特定的字节范围(或多个范围)。 响应中使用 Content-Range 来指示服务器向您提供哪些字节(可能与您请求的范围不同),以及整个内容的长度(如果已知)。

Range is used in the request, to ask for a particular range (or ranges) of bytes. Content-Range is used in the response, to indicate which bytes the server is giving you (which may be different than the range you requested), as well as how long the entire content is (if known).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文