WebRequest, WebRequest.Create GetResponse() GetResponseStream()
作者:互联网
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); } } } }
标签:rs,res,Create,req,GetResponseStream,WebRequest,using 来源: https://www.cnblogs.com/Fred1987/p/13071203.html