Beispiel #1
0
            static void Main()
            {
                //将web响应写入磁盘
                //WebRequest request=WebRequest.Create("http://manning.com");
                //using (WebResponse response = request.GetResponse())
                //using (Stream responseStream = response.GetResponseStream())
                //using (FileStream output = File.Create("response.dat"))
                //{
                //    StreamUtil.Copy(responseStream, output);
                //}
                //使用扩展方法调用:
                WebRequest request = WebRequest.Create("http://manning.com");

                using (WebResponse response = request.GetResponse())
                    using (Stream responseStream = response.GetResponseStream())
                        using (FileStream output = File.Create("response.dat"))
                        {
                            //responseStream.CopyTo(output);//没有使用扩展方法
                            StreamUtil.CopyTo(responseStream, output);
                        }
                Console.ReadKey();
            }