Deciding between HttpClient and WebClient

后端 未结 6 1291
情话喂你
情话喂你 2020-11-22 14:37

Our web app is running in .Net Framework 4.0. The UI calls controller methods through ajax calls.

We need to consume REST service from our vendor. I am evaluating

6条回答
  •  借酒劲吻你
    2020-11-22 15:31

    Unpopular opinion from 2020:

    When it comes to ASP.NET apps I still prefer WebClient over HttpClient because:

    1. The modern implementation comes with async/awaitable task-based methods
    2. Has smaller memory footprint and 2x-5x faster (other answers already mention that)
    3. It's suggested to "reuse a single instance of HttpClient for the lifetime of your application". But ASP.NET has no "lifetime of application", only lifetime of a request.

提交回复
热议问题