J
Jack
Hi,
I want to read a string a chars from a stream, and put it into a
string.
At the moment, I'm creating a buffer of a fixed size, and reading the
stream of text into it. It works, but I have to create a buffer of a
pre-defined length: (ConstBufferByteSize=10000000). How can I read a
stream into a buffer or string without knowing the number of chars the
stream will contain?
Dim response As HttpWebResponse
Dim responseStream As Stream
....
' Do the Request
response = CType(request.GetResponse(), HttpWebResponse) ' Get the
response from the server, and put it into a HttpWebResponse
responseStream = response.GetResponseStream() ' Get the
XML Response stream
' Now put the text received into a buffer
Dim tempBuffer(ConstBufferByteSize) As Byte
Dim enc As New System.Text.ASCIIEncoding
responseStream.Read(tempBuffer, 0, ConstBufferByteSize) ' Read
from the stream x bytes and put into a temporary buffer of fixed size
responseStream.Close() ' Close
the request stream to free up resources
strResponse = enc.GetString(tempBuffer) ' Put the response
into a string (finally!)
MessageBox.Show(strResponse)
Thanks in advance,
Jack.
I want to read a string a chars from a stream, and put it into a
string.
At the moment, I'm creating a buffer of a fixed size, and reading the
stream of text into it. It works, but I have to create a buffer of a
pre-defined length: (ConstBufferByteSize=10000000). How can I read a
stream into a buffer or string without knowing the number of chars the
stream will contain?
Dim response As HttpWebResponse
Dim responseStream As Stream
....
' Do the Request
response = CType(request.GetResponse(), HttpWebResponse) ' Get the
response from the server, and put it into a HttpWebResponse
responseStream = response.GetResponseStream() ' Get the
XML Response stream
' Now put the text received into a buffer
Dim tempBuffer(ConstBufferByteSize) As Byte
Dim enc As New System.Text.ASCIIEncoding
responseStream.Read(tempBuffer, 0, ConstBufferByteSize) ' Read
from the stream x bytes and put into a temporary buffer of fixed size
responseStream.Close() ' Close
the request stream to free up resources
strResponse = enc.GetString(tempBuffer) ' Put the response
into a string (finally!)
MessageBox.Show(strResponse)
Thanks in advance,
Jack.