跟踪网页下载进度 [英] Track webpage downloading progress

查看:28
本文介绍了跟踪网页下载进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这段 VB.NET 代码从网站下载文本:

I'm using this piece of code for VB.NET to download the text from a website:

Dim Str As System.IO.Stream
        Dim srRead As System.IO.StreamReader
        Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://www.example.com/file.txt")
        Dim resp As System.Net.WebResponse = req.GetResponse
        Str = resp.GetResponseStream
        srRead = New System.IO.StreamReader(Str)

它只是一个文本文件,而且很小,所以下载速度非常快.但我相信在未来这个文件会变得相当大.有没有办法通过上述方法跟踪下载进度?

It is just a text file, and is rather small, so it downloads really quickly. But I do believe that in the future the file will become considerably large. Is there a way to track the downloading progress from the above method?

推荐答案

您可以在 WebResponse 对象的 ContentLength 属性中找到查找的总长度.完成后,根据您从 GetResponseStream 读取的数据报告进度非常容易.

You can find the total length of your find in the ContentLength property of your WebResponse object. Once you have that, it's pretty easy to report progress based on the data you read from the GetResponseStream.

这篇关于跟踪网页下载进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆