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

后端 未结 5 1000
迷失自我
迷失自我 2020-12-01 09:44

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 pro

5条回答
  •  情深已故
    2020-12-01 10:22

    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.

    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".

    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.

提交回复
热议问题