0

I am downloading a .mp3 file and before download I want to read the header of the file to see if it can has resume support. I read that if it has resume support it will return a response with a status code 206 but I always get status code 200 even I know it has resume support.

For getting status code I am using:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlstring);
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusCode);

Do I need to add more property or try something else entirely?

Alexander Goldabin
  • 1,824
  • 15
  • 17
eomer
  • 3,514
  • 7
  • 30
  • 42
  • Does this answer your question? [How to request only the HTTP header with C#?](https://stackoverflow.com/questions/6237734/how-to-request-only-the-http-header-with-c) – xdtTransform Jan 30 '20 at 12:40
  • 1
    Do a `HEAD` request first, then the GET-request. – Joel Jan 30 '20 at 12:41
  • @Joel I thought I am getting head with this request I am not downloading via this code If I am not requesting HEAD how can I request it? – eomer Jan 30 '20 at 12:44
  • I assume you are not speaking about the file header. Like the first X byte. If it's the case, You can get stream and read only the length you need. webResponse.GetResponseStream() – xdtTransform Jan 30 '20 at 12:44
  • @xdtTransform I can read content length with the response I posted in code but I need to know if it has resume support if it has I can resume the download where I left if not I need to start the download from beginning – eomer Jan 30 '20 at 12:47
  • @xdtTransform I used ```request.Method = "HEAD"``` but no change in the response – eomer Jan 30 '20 at 12:50
  • @xdtTransform the answer you post works great. I didnt know that I should look for accept ranges header thanks – eomer Jan 30 '20 at 13:19

0 Answers0