如何使用.NET中的HTTPClient而不是WebClient下载Excel文件?
我有以下代码
private void SaveFile(string linkToFile, string filename)
{
using WebClient client = new();
client.DownloadFile(linkToFile, ResourcePath + filename);
}
,所以我的问题是,如何使用httpclient而不是WebClient下载Excel文件?
I have the following code
private void SaveFile(string linkToFile, string filename)
{
using WebClient client = new();
client.DownloadFile(linkToFile, ResourcePath + filename);
}
So my question is, how can I download Excel file with HttpClient instead of WebClient?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
httpclient
上的文档的最佳来源当然是Microsoft网站本身:https:// https://learlearn.microsoft.com/en-en-us /dotnet/api/system.net.http.httpclient
这是我用于下载电子表格的代码的(过于简单的)版本:
The best source of documentation on
HttpClient
is, of course, the Microsoft site itself:https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient
Here's an (oversimplified) version of the code I use for downloading spreadsheets: