Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- From: "John Wilmot" <nfr@xxxxxxxxxx>
- Date: Mon, 2 Oct 2006 14:59:15 -0700
The following code-snippet works but is just not elegant, IMO.
Does anyone have a recommendation to make this more efficient?
For example, I prefer NOT to have a static "buf" size. In fact, I would
prefer something similar to StreamReader.ReadToEnd() for returning a string,
but into a byte[] array.
Snippet:
HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
using (BinaryReader reader = new
BinaryReader(webResponse.GetResponseStream(), enc))
{
byte[] buf = new byte[20000];
int count = reader.Read(buf, 0, buf.Length);
byte[] resp = new byte[count];
for (int i = 0; i < count; i++) resp [i] = buf[i];
}
.
- Follow-Ups:
- Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- From: Marc Gravell
- Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- Prev by Date: Re: System dpi
- Next by Date: How do I assign null to an integer?
- Previous by thread: Re: How to Dis/Enable Network Adapter?
- Next by thread: Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- Index(es):