想下载文件的部分字节,为什么request.AddRange()不起作用?
我想从文件中读取一部分字节,可是不知为什么总是读取了整个文件,请各位赐教:原文件大小:3452字节
程序如下:
Dim totalBytes As Integer = 0
Dim fs1 As New FileStream(Path.GetFileNameWithoutExtension("test") + ".$$", FileMode.Create)
Try
Dim rqs As HttpWebRequest
rqs = CType(HttpWebRequest.Create("http://.../templates/jtjy/skins/default/images/jy_01.gif"), HttpWebRequest)
rqs.AddRange(0, 2452)
Dim strm As Stream
strm = rqs.GetResponse.GetResponseStream
Dim receiveBytes(512 - 1) As Byte
Dim readBytes As Integer
readBytes = strm.Read(receiveBytes, 0, receiveBytes.Length)
Do While readBytes > 0
fs1.Write(receiveBytes, 0, readBytes)
totalBytes += readBytes
readBytes = strm.Read(receiveBytes, 0, receiveBytes.Length)
Loop
strm.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try