C# WPF网络请求获取数据

string IP = ConfigurationManager.AppSettings["IP"];
string user = ConfigurationManager.AppSettings["user"];
string passwd = ConfigurationManager.AppSettings["passwd"];
string interlinkage = "/snapshot.cgi?user=" + user + "&pwd=" + passwd;

Uri MyUri = new Uri("http://" + IP + interlinkage);          //实例一个Uri
                                                             //Uri MyUri = new Uri("https://a.300.cn/anliku/180224/0001400345s.jpg");          //实例一个Uri

HttpWebRequest MyHttpWebRequest = WebRequest.Create(MyUri) as HttpWebRequest;
MyHttpWebRequest.Method = "GET";

//获取视屏数据流
//MyHttpWebRequest.GetResponse().GetResponseStream();

//初始化BitmapImage实例Bitmap
BitmapImage Bitmap = new BitmapImage();
Bitmap.BeginInit();
Bitmap.StreamSource = MyHttpWebRequest.GetResponse().GetResponseStream();
Bitmap.EndInit();

//将Bitmap传递给Image的Source属性,在Image控件中显示出摄像头的图像
imgCamera.Source = Bitmap;

你可能感兴趣的:(C#)