获取下载文件长度
程序员文章站
2022-04-08 21:38:28
...
private long getDownLength(string url)
{
long length = 0;
try
{
var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
req.Method = "HEAD";
req.Timeout = 5000;
var res = (HttpWebResponse)req.GetResponse();
if (res.StatusCode == HttpStatusCode.OK)
{
length = res.ContentLength;
}
res.Close();
return length;
}
catch (Exception)
{
return 0;
throw;
}
}
上一篇: 关于inputStream.available()方法获取下载文件的总大小
下一篇: 文件的读与写