我正在尝试检查给定的URL是否支持Range
标头,所以我编写了这样的代码
val client = OkHttpClient()
val request = Request.Builder().url(url)
.addHeader("Range", "bytes=0-0")
.head().build()
val call = client.newCall(request)
val response = call.execute()
val headers = response.headers()
toast("Status Code: ${response.code()}")
if (response.code() == 206) {
return true
} else {
return false
}
,但它在应用程序的第一次运行时返回206
,然后始终返回200
状态代码。我用curl
测试了URL,它返回了状态代码206
curl https://www.html5rocks.com/en/ttorials/video/basics/devstories.webm -i -H "Range: bytes=0-0"
输出
HTTP/2 206
date: Fri, 08 Feb 2019 08:09:31 GMT
expires: Sun, 10 Mar 2019 08:09:31 GMT
etag: "swDXqA"
x-cloud-trace-context: cd931b65d04f94a2157792c68bee6ff9
content-type: audio/webm
server: Google Frontend
cache-control: public, max-age=2592000
content-range: bytes 0-0/6466607
content-length: 1
age: 274249