我有一个ASP.NET应用程序,我需要从安全摄像头显示视频源.视频Feed的内容类型为'multipart/x-mixed-replace; boundary = - myboundary'与边界之间的图像数据.我需要帮助将数据流传递到我的页面,以便我拥有的客户端插件可以像使用直接浏览到摄像头的Web界面一样使用流.以下代码不起作用:
//Get response data
byte[] data = HtmlParser.GetByteArrayFromStream(response.GetResponseStream());
if (data != null)
{
HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length);
}
return;
Run Code Online (Sandbox Code Playgroud) codeplex上的例子是这样的:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{
HtmlAttribute att = link["href"];
att.Value = FixLink(att);
}
doc.Save("file.htm");
Run Code Online (Sandbox Code Playgroud)
第一个问题是HtmlDocument.DocumentElement不存在!存在的是HtmlDocument.DocumentNode,但即使我使用它,我也无法按照描述访问href属性.我收到以下错误:
Cannot apply indexing with [] to an expression of type 'HtmlAgilityPack.HtmlNode'
Run Code Online (Sandbox Code Playgroud)
当我收到此错误时,这是我正在尝试编译的代码:
private static void ChangeUrls(ref HtmlDocument doc)
{
foreach(HtmlNode link in doc.DocumentNode.SelectNodes("//@href"))
{
HtmlAttribute attr = link["href"];
attr.Value = Rewriter(attr.Value);
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我刚刚发现这个例子从来没有打算工作......而且我在阅读了示例代码后得到了一个解决方案......我会为像我这样的其他人发布我的解决方案,一旦完成就可以享受.