Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- From: "John Wilmot" <nfr@xxxxxxxxxx>
- Date: Tue, 3 Oct 2006 08:50:20 -0700
The thing I don't like is having to preallocate a set buffer size.
OTH, I actually started by using webclient but it turned out that it did not
have enough granularity for setting things like timeout values, etc.
"Marc Gravell" <marc.gravell@xxxxxxxxx> wrote in message
news:1159852050.903599.141200@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Snippet is unreliable; assumes < 20K bytes, and manual copy (instead of
buf.CopyTo() or Buffer.BlockCopy()) is inneficient. Perhaps read (in a
loop, using a smaller buffer) from the response and writing to a
MemoryStream, then call ms.ToArray()? This would work with any size.
In 2.0, you could instead use WebClient:
byte[] data;
using (WebClient wc = new WebClient()) {
data = wc.DownloadData("http://somewhere");
}
Marc
.
- 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?
- From: Joerg Jooss
- 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?
- References:
- Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- From: John Wilmot
- Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- From: Marc Gravell
- Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- Prev by Date: Unit Testing Model-View-Presenter
- Next by Date: Re: Treat a DataSet as a class structure
- Previous by thread: Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- Next by thread: Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?
- Index(es):