Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

c# - How to use WebClient with .NetCore?

Is there any way to use a WebClient in a .NET Core application? 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As of .Net Standard 2.0, WebClient is now available to any implementations of the standard, including .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.

One of the drawbacks mentioned is that there is no built-in progress reporting in the 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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...