Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C检查m3u8 web url#_C#_M3u8 - Fatal编程技术网

C# 使用C检查m3u8 web url#

C# 使用C检查m3u8 web url#,c#,m3u8,C#,M3u8,我正在程序中执行一个小功能,我想检查m3u8链接是否正常工作。但是,我无法正确执行此操作,因为某些链接不工作,但它们返回的状态代码等于OK。这是我的密码: var textBox = (TextBox)this.FindName("urlToCheck"); var request = (HttpWebRequest)WebRequest.Create(textBox.Text.Trim()); request.Method = "HEAD"; try { var r

我正在程序中执行一个小功能,我想检查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播放器

非常感谢你的帮助


致以最诚挚的问候

最后,我通过检查链接的状态代码和contentlength来修复它:


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

定义“不工作”。根据定义,返回200的请求是有效的——它返回了您在正文中要求的任何内容。如果你想确认身体是你所期望的,你应该检查身体的内容,而不是状态码。嗯,例如,这里我们有国际空间站的空间站流:这个在工作,而这个:不工作。我不知道如何准确地检测差异,对我来说,检测差异的方法是使用VLC播放器。