c # video downloads

pathUrl = String "";
the System.Net.HttpWebRequest Request = null;
System.Net.HttpWebResponse Response = null;
// network path request address
request = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (pathUrl );
request.Timeout = 5000; // timeout
// get request result
Response = (System.Net.HttpWebResponse) request.GetResponse ();
// file Download
string path = "E: / Download";
// if not presence created file folder
IF (Directory.Exists (path)!)
{
IF (path = null!) Directory.CreateDirectory (path);
}
path = path + "/20190402035457.mp4";
Stream Stream response.GetResponseStream = ( );
// create the file
Stream sos = new System.IO.FileStream (path, System.IO.FileMode.Create);
byte[] img = new byte[1024];
int total = stream.Read(img, 0, img.Length);
while (total > 0)
{
//之后再输出内容
sos.Write(img, 0, total);
total = stream.Read(img, 0, img.Length);
}
stream.Close();
stream.Dispose();
sos.Close();
sos.Dispose();

Guess you like

Origin www.cnblogs.com/wangzhenghao/p/11235642.html