我有以下代码:
With context.Response
Dim req As HttpWebRequest = WebRequest.Create("http://www.Google.com/")
req.Proxy = Nothing
Dim res As HttpWebResponse = req.GetResponse()
Dim Stream As Stream = res.GetResponseStream
.OutputStream.Write(Stream, 0, Stream.Length)
End With遗憾的是,上面的代码不起作用。我需要将RequestStream从context.Response放到OutputStream中。
有什么想法吗?
发布于 2011-03-14 17:34:07
Write接受一个字节数组,而你给它传递的是一个流。
尝试从流中读取并获取所有数据,然后将其写回。
首先,将数据读入中间字节数组(Taken from here):
Dim bytes(Stream.Length) As Byte
Dim numBytesToRead As Integer = s.Length
Dim numBytesRead As Integer = 0
Dim n As Integer
While numBytesToRead > 0
' Read may return anything from 0 to 10.
n = Stream.Read(bytes, numBytesRead, 10)
' The end of the file is reached.
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
Stream.Close()然后将其写入输出流:
.OutputStream.Write(bytes, 0, Stream.Length) https://stackoverflow.com/questions/5296468
复制相似问题