如何确定服务器是否支持 Range 标头? [英] How can I find out whether a server supports the Range header?

查看:13
本文介绍了如何确定服务器是否支持 Range 标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Range 标头值从特定点流式传输音频,但我总是从一开始就得到歌曲.我是通过程序执行此操作的,因此不确定问题出在我的代码还是服务器上.

I have been trying to stream audio from a particular point by using the Range header values but I always get the song right from the beginning. I am doing this through a program so am not sure whether the problem lies in my code or on the server.

如何判断服务器是否支持 Range 标头参数?

How can I find out whether the server supports the Range header param?

谢谢.

推荐答案

HTTP spec 定义了它,如果服务器知道如何支持 Range 标头,它会.这反过来又要求它返回 206 部分内容 带有 Content-Range 的响应代码 标头,当它向您返回内容时.否则,它将简单地忽略您请求中的 Range 标头,并返回 200 响应代码.

The way the HTTP spec defines it, if the server knows how to support the Range header, it will. That in turn, requires it to return a 206 Partial Content response code with a Content-Range header, when it returns content to you. Otherwise, it will simply ignore the Range header in your request, and return a 200 response code.

这可能看起来很愚蠢,但是您确定您正在制作一个有效的 HTTP 请求标头吗?太常见了,我忘记在请求中指定 HTTP/1.1,或者忘记指定范围说明符,例如字节".

This might seem silly, but are you sure you're crafting a valid HTTP request header? All too commonly, I forget to specify HTTP/1.1 in the request, or forget to specify the Range specifier, such as "bytes".

哦,如果您只想检查,那么只需发送 HEAD 请求而不是 GET 请求.相同的标题,相同的一切,只是HEAD"而不是GET".如果您收到 206 响应,您将知道 Range 受支持,否则您将收到 200 响应.

Oh, and if all you want to do is check, then just send a HEAD request instead of a GET request. Same headers, same everything, just "HEAD" instead of "GET". If you receive a 206 response, you'll know Range is supported, and otherwise you'll get a 200 response.

这篇关于如何确定服务器是否支持 Range 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆