Download and save a picture from a url Universal windows app

时间秒杀一切 提交于 2019-12-04 12:10:17

I am not seeing any error in my code. But after trying some different ways of downloading and saving a file my code looks like this and

 try
            {
                HttpClient client = new HttpClient(); // Create HttpClient
                byte[] buffer = await client.GetByteArrayAsync(coverUrl); // Download file
                using (Stream stream = await coverpic_file.OpenStreamForWriteAsync())
                    stream.Write(buffer, 0, buffer.Length); // Save
            }
            catch
            {
                saved = false;
            }

And this code is working fine without causing any issues All images are downloading completely and no more issues of black block on images.

If any one can points out the difference with my first code will be really helpful to understood the reason for error

Ask Too Much

Have you tried using new Windows.Web.Http.HttpClient instead of HttpWebRequest?

Also take a look this SO question : How do I use the new HttpClient from Windows.Web.Http to download an image?

If you not familiar with HttpClient, I sugest to watch CH9 presentation : https://channel9.msdn.com/Events/Build/2013/4-092

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!