I try to download a video (any) from the Sibnet service, test for receiving a link to a video file, and successfully receive a normal Url , but at the same time, if you make a request to read a data stream, nothing happens and the data stream is always empty, although the response code is 200 .
In general, in order to get a link to the file, you need to do the following, get a link to the mpd file, rename mpd to mp4 , and make a request. If you do all this using a browser, it turns out that when you request the Url , you are redirected to one of the sibnet servers where the file is located (or rather, access from there will be allowed, the link is always different) . In my case, when requesting such an Url redirection occurs, and HttpClient simply reads the response of the headers, no more.
The code below is operational, but cannot read the content.
What can be done so that the content can be read, and so that the redirection works?
public class Program { public static void Main(string[] args) { CookieCollection cookieCollection = new CookieCollection(); CookieContainer container = new CookieContainer(); container.Add(cookieCollection); HttpClientHandler clientHandler = new HttpClientHandler { AllowAutoRedirect = true, UseCookies = true }; HttpClient client = new HttpClient(clientHandler, true) { BaseAddress = new Uri("https://video.sibnet.ru/") }; string result = client.GetStringAsync ( new Uri( "/shell.php?videoid=3490241", UriKind.Relative) ).GetAwaiter().GetResult(); Regex regex = new Regex(@"\[\{src\:\s?\""(?<FilePath>[^\""]+)\"""); Match match = regex.Match(result); Console.WriteLine(match.Groups["FilePath"].Value.Replace("mpd", "mp4").Replace("m3u8", "mp4")); client.DefaultRequestHeaders.Referrer = new Uri(client.BaseAddress.OriginalString + "/shell.php?videoid=3490241"); client.DefaultRequestHeaders.Add("Origin", "https://video.sibnet.ru"); HttpResponseMessage message = client .GetAsync(new Uri(match.Groups["FilePath"].Value.Replace("mpd", "mp4").Replace("m3u8", "mp4"), UriKind.Relative)).GetAwaiter().GetResult(); message = message.EnsureSuccessStatusCode(); Stream fileData = message.Content.ReadAsStreamAsync().GetAwaiter().GetResult(); FileStream file = File.Create("sibnet.mp4"); byte[] data = new byte[8388608]; // 8 Mb 1024*1024*8 int offset = 0; while ((offset = fileData.Read(data, 0, data.Length)) != 0) file.Write(data, offset, data.Length); file.Close(); fileData.Close(); client.Dispose(); }