文件下载问题
我写了下面一个下载文集的类可有两个问题一直没有解决
一、文件的大小老不对 二、文件不能完整地下载我用的测试地址是 http://wttele2.skycn.com/down/Behead.zip
发现长度GetSize老是等于7233
请高手指教 下面是这个类的代码
Imports System.net
Imports System.IO
Public Class clsHTTP
Dim url As String
Dim lngSize As Long
Dim htpRequest As HttpWebRequest
Dim htpResponse As HttpWebResponse
Sub New(ByVal strurl As String)
url = strurl
Connect()
End Sub
Sub Connect()
Try
htpRequest = HttpWebRequest.Create(url)
htpRequest.Timeout = 3000
htpResponse = htpRequest.GetResponse
Catch ex As Exception
Return
End Try
End Sub
Function GetSize() As Long
Try
eturn htpResponse.ContentLength
Catch ex As Exception
Return 0
End Try
End Function
Sub DonwLoad(ByVal path As String)
'If File.Exists(path) Then
Dim strmFile As New FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
'End If
Dim strm As Stream = htpResponse.GetResponseStream
Dim strmSize As Integer
Dim offset As Integer = 1048576 '= Me.GetSize
Dim strmByte(1024) As Byte
strmSize = strm.Read(strmByte, 0, strmByte.Length)
While strmSize > 0
strmFile.Write(strmByte, 0, strmSize)
strmSize = strm.Read(strmByte, 0, strmByte.Length)
End While
End Sub
End Class