【问题标题】:Check m3u8 web url with C#使用 C# 检查 m3u8 网址
【发布时间】:2015-09-14 13:14:56
【问题描述】:

我正在一个程序中执行一个小功能,我想检查一个 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 Stream 而不是。现在对我来说唯一的方法是使用 VLC 播放器。

非常感谢您的帮助。

最好的问候

【问题讨论】:

标签: c# m3u8


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-03-01
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-13
    • 2020-09-06
    • 1970-01-01
    相关资源
    最近更新 更多