本帖最后由 百元大户 于 2020-11-20 20:33 编辑
写了一下
[C#] 纯文本查看 复制代码
private static void WhatYouWant(string a)
{
switch (a)
{
case "0":
//MessageBox.Show("正常");
Console.WriteLine("正常");
break;
case "1":
if (HttpDownload("https://down.52pojie.cn/Tools/NET/dnSpy.zip", @"D:\dnSpy.zip"))
Console.WriteLine("下载完成");
break;
case "2":
Process.Start(@"D:\ip.exe");
break;
}
}
private static bool HttpDownload(string url, string path)
{
try
{
using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
using (Stream responseStream = response.GetResponseStream())
{
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, bArr.Length);
while (size > 0)
{
fs.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, bArr.Length);
}
return true;
}
}
}
catch (Exception)
{
return false;
}
}
|