我在程序中做了一个小函数,我想检查一下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播放器。
非常感谢你的帮助。
诚挚的问候
发布于 2015-11-16 10:07:23
最后,我通过检查链接的状态代码和内容长度来修复它:
var success = response.StatusCode == HttpStatusCode.OK && response.ContentLength > 0;
https://stackoverflow.com/questions/32565804
复制相似问题