Stream如何转为Byte()
Dim retBytes() As Byte Dim weq As System.Net.HttpWebRequest Dim wer As System.Net.HttpWebResponse Dim stream As System.IO.Stream Dim ms As New System.IO.MemoryStream Try weq = CType(System.Net.WebRequest.Create(sPath), System.Net.HttpWebRequest) wer = CType(weq.GetResponse(), System.Net.HttpWebResponse) stream = wer.GetResponseStream() '''现在这个stream如何转为byte '''retBytes=?????? Catch ex As Exception Dim err As String = ex.Message Finally ms.Close() wer.Close() End Try
dim bytdata(stream.Length) as bytestream.Position =0stream.Read(bytedata,0,stream.Length)
[解决办法]
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim retBytes() As Byte Dim sPath As String = "http://www.baidu.com" Dim weq As System.Net.HttpWebRequest Dim wer As System.Net.HttpWebResponse Dim stream As System.IO.BinaryReader 'Dim ms As New System.IO.MemoryStream Try weq = CType(System.Net.WebRequest.Create(sPath), System.Net.HttpWebRequest) wer = CType(weq.GetResponse(), System.Net.HttpWebResponse) stream = New IO.BinaryReader(wer.GetResponseStream()) ReDim retBytes(wer.ContentLength - 1) stream.Read(retBytes, 0, wer.ContentLength) '''现在这个stream如何转为byte '''retBytes=?????? Catch ex As Exception Dim err As String = ex.Message Finally 'ms.Close() stream.Close() wer.Close() End Try End SubEnd Class
[解决办法]
忘了减1了
dim bytdata(stream.Length-1) as byte
不好意思,不太习惯