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);
                    }
                }
            }
        }

 

上一篇:Unity在IOS上下载texture后显示红色的问号,但是在unity中运行正常


下一篇:从向量空间的角度来理解方程组有无解的问题