我正在使用以下代码获取IP摄像机流:
private void Display()
{
try
{
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Credentials = new NetworkCredential("username", "password");
HttpWebResponse myHttpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.AppendHeader("Content-Type", "video/mp4");
using (BinaryReader binaryReader = new BinaryReader(receiveStream))
{
byte[] buffer = new byte[100000];
while (true)
{
int nbrByte = receiveStream.Read(buffer, 0, buffer.Length);
if (nbrByte == 0)
break;
Response.OutputStream.Write(buffer, 0, nbrByte);
Response.Clear();
//Response.Flush();
}
}
}
catch (Exception ex)
{
string errMsg = ex.Message;
}
}
运行代码时没有发生任何事情。使用浏览器,登录后我可以看到视频。我错过了什么吗?