Html HTTP 206 Partial Content 状态消息是什么意思,我该如何完全加载资源?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15787380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:10:13  来源:igfitidea点击:

What does the HTTP 206 Partial Content status message mean and how do I fully load resources?

htmlapacherequesthttp-response-codes

提问by prasadmsvs

I have some image tags on a site like this.

我在这样的网站上有一些图片标签。

<img src="img.png"/>

When I try to load them they are only half loading. When I checked the request in the network console I see that the response is:

当我尝试加载它们时,它们只加载了一半。当我在网络控制台中检查请求时,我看到响应是:

206 Partial Content

206 部分内容

I googled it and it says that if there is a range set in header, it will be like this. But where are these headers actually set? And how do I avoid this and load the full images?

我用谷歌搜索它,它说如果标题中设置了一个范围,它将是这样的。但是这些标头实际上在哪里设置?以及如何避免这种情况并加载完整图像?

回答by csaron92

From user166390's answerto the question Why does Firebug show a "206 Partial Content" response on a video loading request?

来自 user166390为什么 Firebug 在视频加载请求上显示“206 Partial Content”响应的问题的回答

This Partial Content code (206) maybe sent from the server when the client has asked for a range (e.g. "give me the first 2MB of video data").

It is vital for downloading data in chunks which avoids fetching unused resources. (I seldom watch a full video online.) Look at the outgoing request for a Rangeheader.

当客户端请求一个范围(例如“给我第一个 2MB 视频数据”)时,该部分内容代码(206)可以从服务器发送。

分块下载数据以避免获取未使用的资源至关重要。(我很少在线观看完整的视频。)查看对Range标头的传出请求。

回答by Penfold

It's up to the client to put in another call to get the rest of the data (or the next bit). You don't have to do anything, they'll get the full image eventually, even if it takes several http calls.

由客户端进行另一次调用以获取其余数据(或下一位)。你不需要做任何事情,他们最终会得到完整的图像,即使需要多次 http 调用。

回答by Aran Mulholland

Firstly:

首先:

The HTTP 206 Partial Contentsuccess status response code indicates that the request has succeeded and has the body contains the requested ranges of data, as described in the Rangeheader of the request.

HTTP206 Partial Content成功状态响应代码表示请求已成功,并且正文包含请求的数据范围,如Range请求标头中所述。

If there is only one range, the Content-Typeof the whole response is set to the type of the document, and a Content-Rangeis provided.

如果只有一个范围,则将Content-Type整个响应的 设置为文档类型,并Content-Range提供 a。

If several ranges are sent back, the Content-Typeis set to multipart/byterangesand each fragment covers one range, with Content-Rangeand Content-Typedescribing it.

如果发回多个范围,则将Content-Type设置为multipart/byteranges并且每个片段覆盖一个范围,Content-Range并对其进行Content-Type描述。

(From Mozilla's excellent HTTP status code reference.)

来自 Mozilla 的优秀 HTTP 状态代码参考。

Next:

下一个:

HTTP headers set on resources are usually set by the web server. However if the file is large, like a video file the browser can request a chunkof the resource that is being loaded. Usually a HTTP 206header will be returned from a client initiated request. The headers set on resources in apache are set in the mod_headerssection of the httpd.conf. Look for the following line to see if partial content is turned on:

在资源上设置的 HTTP 标头通常由 Web 服务器设置。但是,如果文件很大,比如视频文件,浏览器可以请求正在加载的资源。通常一个HTTP 206标头将从客户端发起的请求中返回。在Apache中的资源设置的报头中设置mod_headers的部分httpd.conf。查找以下行以查看部分内容是否已打开:

Header set Accept-Ranges bytes

This section controls the behavior of headers set by apache so it will be a good place to start.

本节控制由 apache 设置的标头的行为,因此它将是一个很好的起点。

Setting the headers can however be done in a number of different ways. For example when using apache you can control the images that are loaded so that they will cache. This can be done using the [a2enmod module][2]. This will reduce the load on your server.

然而,可以通过多种不同的方式设置标题。例如,当使用 apache 时,您可以控制加载的图像,以便它们缓存。这可以使用[a2enmod module][2]. 这将减少服务器上的负载。

回答by thiago marini

I had similar problem when loading fonts from different subdomains. In my case I was getting 206 due to crossdomain issues and I solved it just by putting a .htaccess file in my root folder:

从不同的子域加载字体时,我遇到了类似的问题。在我的情况下,由于跨域问题,我得到了 206,我只是通过在我的根文件夹中放置一个 .htaccess 文件来解决它:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>