Check m3u8 web url with C#

本文关键字:with url web m3u8 Check | 更新日期: 2023-09-27 18:12:35

我正在程序中执行一个小函数,我想检查m3u8链接是否正常工作。然而,我不能正确地做到这一点,因为一些链接不工作,但他们返回的状态码等于OK。这是我的代码:

var textBox     = (TextBox)this.FindName("urlToCheck");
var request     = (HttpWebRequest)WebRequest.Create(textBox.Text.Trim());
request.Method  = "HEAD";
try
{
    var response = (HttpWebResponse)request.GetResponse();
    var success  = response.StatusCode == HttpStatusCode.OK;
    if (success) MessageBox.Show("Apparently the link is working");
    else MessageBox.Show("Apparently the link is not working");
}
catch (Exception)
{
    MessageBox.Show("Tthe link is not working");
}

如何检测工作链接中是否有真正的流?我不确定如何做到这一点,如何检测一个工作的URL流和一个不是。现在对我来说,唯一的方法就是使用VLC播放器。

非常感谢你的帮助。

Check m3u8 web url with C#

最后我通过检查链接的状态代码和内容长度来修复它:

var success = response.StatusCode == HttpStatusCode.OK && response.ContentLength > 0;