static void WebRequestDemo() { WebRequest req = WebRequest.Create("https://5b0988e595225.cdn.sohucs.com/images/20180422/bd1d3910de4945a7996eee3c1eedd023.jpeg"); req.Proxy = null; using (WebResponse res = req.GetResponse()) { using (Stream rs = res.GetResponseStream()) { using (FileStream fs = File.Create("c.jpeg")) { rs.CopyTo(fs); } } } }
static async void WebRequestAsync() { WebRequest req = WebRequest.Create("https://5b0988e595225.cdn.sohucs.com/images/20180422/bd1d3910de4945a7996eee3c1eedd023.jpeg"); req.Proxy = null; using(WebResponse res=await req.GetResponseAsync()) { using(Stream rs=res.GetResponseStream()) { using (FileStream fs = File.Create("d.jpg")) { await rs.CopyToAsync(fs); } } } }