Save what you read from WebRequest to a file : WebRequest « Network « C# / CSharp Tutorial






using System.ComponentModel;
using System.IO;
using System.Net;

    class MainClass
    {
        static void Main()
        {
            WebRequest request = WebRequest.Create("http://java2s.com");
            using (WebResponse response = request.GetResponse())
            using (Stream responseStream = response.GetResponseStream())
            using (FileStream output = File.Create("response.dat"))
            {
                Copy(responseStream, output);
            }
        }
        
        const int BufferSize = 8192;

        public static void Copy(Stream input,Stream output)
        {
            byte[] buffer = new byte[BufferSize];
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                output.Write(buffer, 0, read);
            }
        }

        public static byte[] ReadFully(Stream input)
        {
            using (MemoryStream tempStream = new MemoryStream())
            {
                Copy(input, tempStream);
                if (tempStream.Length == tempStream.GetBuffer().Length)
                {
                    return tempStream.GetBuffer();
                }
                return tempStream.ToArray();
            }
        }        
    }








33.20.WebRequest
33.20.1.Use WebRequest
33.20.2.Use WebRequest and WebResponse to read a web page
33.20.3.Download image from a website
33.20.4.Use WebRequest to create a StreamReader
33.20.5.Save what you read from WebRequest to a file
33.20.6.Reading Web Page As HTML
33.20.7.Use WebRequest to read csv file from finance.yahoo.com