通过 HTTP 将文件下载到 C# 中的字节数组中? [英] Download a file over HTTP into a byte array in C#?

查看:40
本文介绍了通过 HTTP 将文件下载到 C# 中的字节数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我有网址的文件读取到字节数组中.我一直在使用 File.ReadAllBytes 在本地读取文件,但我一直无法找出对网络上的文件执行此操作的最简洁方法.

I'm trying to read a file that I have a web address for into a byte array. I've been using File.ReadAllBytes to read files locally and I've been unable to figure out the cleanest way to do this for a file on the web.

我想这只是一小段代码,但我可以通过搜索找到的所有内容仅适用于本地文件.

I imagine this is just a quick snippet of code, but everything I can find through search is only for local files.

推荐答案

byte[] response = new System.Net.WebClient().DownloadData(url);

这篇关于通过 HTTP 将文件下载到 C# 中的字节数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆