<p>What is the best way to read an HTTP response from GetResponseStream ?</p>

<p>Currently I'm using the following approach.</p>

<pre><code>Using SReader As StreamReader = New StreamReader(HttpRes.GetResponseStream)
   SourceCode = SReader.ReadToEnd()
End Using
</code></pre>

<p>I'm not quite sure if this is the most efficient way to read an http response.</p>

<p>I need the output as string, I've seen an <a href="http://www.informit.com/guides/content.aspx?g=dotnet&amp;seqNum=583" rel="noreferrer">article</a> with a different approach but I'm not quite if it's a good one. And in my tests that code had some encoding issues with in different websites.</p>

<p>How do you read web responses?</p>

I use something like this to download a file from a URL:
```
```
if (!Directory.Exists(localFolder))
{
    Directory.CreateDirectory(localFolder);   
}

try
{
    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(Path.Combine(uri, filename));
    httpRequest.Method = "GET";

    // if the URI doesn't exist, an exception will be thrown here...
    using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
    {
        using (Stream responseStream = httpResponse.GetResponseStream())
        {
            using (FileStream localFileStream = 
                new FileStream(Path.Combine(localFolder, filename), FileMode.Create))
            {
                var buffer = new byte[4096];
                long totalBytesRead = 0;
                int bytesRead;

                while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    totalBytesRead += bytesRead;
                    localFileStream.Write(buffer, 0, bytesRead);
                }
            }
        }
    }
}
catch (Exception ex)
{
    // You might want to handle some specific errors : Just pass on up for now...
    // Remove this catch if you don't want to handle errors here.
    throw;
}
```
```