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

查看:100
本文介绍了如何确定服务器是否支持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标头param?

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

谢谢。

推荐答案

HTTP规范定义它,如果服务器知道如何支持范围标题,它会。反过来,要求它返回 206 Partial Content 使用 Content-Range <的响应代码/ code> 标题,当它向您返回内容时。否则,它将忽略您请求中的 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,或者忘记指定范围说明符,例如bytes。

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天全站免登陆