How to convert WebResponse.GetResponseStream return into a string?

Joan Venge picture Joan Venge · Sep 25, 2011 · Viewed 129.4k times · Source

I see many examples but all of them read them into byte arrays or 256 chars at a time, slowly. Why?

Is it not advisable to just convert the resulting Stream value into a string where I can parse it?

Answer

kv-prajapati picture kv-prajapati · Sep 25, 2011

You can use StreamReader.ReadToEnd(),

using (Stream stream = response.GetResponseStream())
{
   StreamReader reader = new StreamReader(stream, Encoding.UTF8);
   String responseString = reader.ReadToEnd();
}