我之前在下载 rar 文件时遇到了问题,服务器没有为 rar 配置,所以我决定给一个 go zip,这里又是另一个问题。我添加了一个异常并得到这样的消息:“指定的参数超出了有效值的范围。参数名称:大小”文件大约 100KB。期待您的帮助,谢谢。
这是我的代码:
request = Net.HttpWebRequest.Create("http://webserver.com/test/zip")
request.CookieContainer = logincookie
request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0 Java/1.7.0"
request.Method = "GET"
response = request.GetResponse()
If Not response.ContentType = "application/zip" Then
MsgBox("Error: " & ErrorToString() & vbCrLf & "Current file name is : " & response.ContentType.ToString)
Exit Sub
End If
Dim intLen As Int32 = response.ContentLength
Dim memStream As MemoryStream
Using stmResponse As IO.Stream = response.GetResponseStream()
Dim buffer = New Byte(intLen) {}
Dim bytesRead As Integer
Do
bytesRead += stmResponse.Read(buffer, bytesRead, intLen - bytesRead)
Loop Until bytesRead = intLen
memStream = New MemoryStream(buffer)
My.Computer.FileSystem.WriteAllBytes("test.zip", buffer, False)
End Using
End If