代码如下:
private void getSpeed()
{
//链接开始时间
DateTime stime = DateTime.Now;
//文件
string url = "http://xxx.com/images/test.jpg ";
WebRequest myRequest = WebRequest.Create(url);
//链接成功
WebResponse myReponse = myRequest.GetResponse();
//取得文件的大小 字节单位
int ii = int.Parse(myReponse.ContentLength.ToString());
//取得流
Stream myStream = myReponse.GetResponseStream();
StreamReader sr = new StreamReader(myStream);
byte[] mbyte=new byte[ii];
int allbyte=(int)mbyte.Length;
int startbyte=0;
string test = " ";
while(ii> 0) //################ 循环读取文件,并显示进度.....
{
int m=myStream.Read(mbyte,startbyte,allbyte);
if(m==0){break;}
startbyte+=m;
allbyte-=m;
int a1=(int)startbyte/1024;
int a2=(int)ii/1024;
test+= "连接成功..开始下载..m= "+m+ "| " + a1.ToString() + "/ " + a2.ToString() + "KB ";//startbyte + "/ " + ii.ToString();
}
//链接结束时间
DateTime etime=DateTime.Now;
TimeSpan ts = etime - stime;
//总共耗时
double SpeedTime = (double) ts.TotalSeconds;
double Kbps = 0;
double ShowPer = 0;
新闻热点
疑难解答
图片精选