简体   繁体   English

如何在.NetCore中使用WebClient?

[英]How to use WebClient with .NetCore?

Is there any way to use a WebClient in a .NET Core application? 有什么方法可以在.NET Core应用程序中使用WebClient If I build the application I get the following error: 如果我构建应用程序,则会出现以下错误:

Severity    Code    Description Project File    Line
Error   CS0246  The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)

I think WebClient is not a part of .NET Core, but is there any alternative? 我认为WebClient不是.NET Core的一部分,但是还有其他选择吗?

As of .Net Standard 2.0, WebClient is now available to any implementations of the standard, including .Net Core. 从.Net Standard 2.0开始,WebClient现在可用于该标准的任何实现,包括.Net Core。 However, the Stack Overflow question " Need help deciding between HttpClient and WebClient " has some fairly good answers as to why you should be using the HttpClient instead. 但是,堆栈溢出问题“ 需要帮助来决定HttpClient和WebClient之间的关系 ”对于为什么应使用HttpClient却有一些相当不错的答案。

One of the drawbacks mentioned is that there is no built-in progress reporting in the HttpClient . 提到的缺点之一是HttpClient没有内置的进度报告。 However, because it is using streams, it is possible to write your own. 但是,由于它使用流,因此可以编写自己的流。 The answers to " How to implement progress reporting for Portable HttpClient " provides an example for reporting the progress of the response stream. 如何为Portable HttpClient实现进度报告 ”的答案提供了一个报告响应流进度的示例。

If you're targeting prior versions of the standard, you'll need to use HttpClient as WebClient is not available prior to .Net Standard 2.0. 如果您要针对该标准的HttpClient版本,则需要使用HttpClient因为.Net Standard 2.0之前WebClient不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 netcore 2.2 中使用 Basic Auth - How to use Basic Auth in netcore 2.2 如何在 .netcore 6 razor 页面中使用 FormHelper 和 FluentValidation - How to use FormHelper and FluentValidation in .netcore 6 razor pages 如何使用WebClient通过[FromBody] POST到WebAPI - How to use WebClient to POST to WebAPI using [FromBody] 如何指定用于 WebClient 类的 SSL 协议 - How to specify SSL protocol to use for WebClient class 如何在 WebClient.DownloadStringAsync URL 中使用 String - How to use String in WebClient.DownloadStringAsync URL 如何在WebApi中使用AuthorizationFilterAttribute和WebClient库? - How use AuthorizationFilterAttribute in WebApi with WebClient Library? 如何在WebClient请求中使用动词GET? - How to use verb GET with WebClient request? 如何在此上下文中使用WebClient.DownloadDataAsync()方法? - How to use the WebClient.DownloadDataAsync() method in this context? 如何在不阻塞 UI 的情况下使用 WebClient? - How to use WebClient without blocking UI? 如何配置与Webpack的.netcore代理连接以使用HTTP而不是HTTPS - How to configure .netcore proxy connection to webpack to use HTTP not HTTPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM