Re: Is there a clean way to create a byte[] from an HttpWebRequest.Read?



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

.



Relevant Pages

  • Re: WebClient Timeout Exception
    ... > I have a problem with the WebClient and uploading a file to a web server. ... > Buffer length is around 4 MB. ... > Writing a 2k chunk and calling flush until the entire buffer is read ... > Writing a webservice method that takes an array of bytes> ...
    (microsoft.public.dotnet.languages.csharp)
  • Passing security credentials to ASP from .net
    ... WebClient wc = new WebClient; ... NameValueCollection nvc = new NameValueCollection; ... buffer = wc.UploadValues; ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • WebClient Timeout Exception
    ... I have a problem with the WebClient and uploading a file to a web server. ... Buffer length is around 4 MB. ... Writing a 2k chunk and calling flush until the entire buffer is read ...
    (microsoft.public.dotnet.languages.csharp)