HttpClient vs HttpWebRequest

前端 未结 3 1245
一向
一向 2020-12-02 15:27

I have a large file which I have to send to a web api client...The data is multi part. The issue is , if the file is sent over http web request, then it is uploaded quickly

3条回答
  •  暖寄归人
    2020-12-02 15:52

    HttpClient is more like a head-less browser. It a powerfull and ideal tool if you are going to be creating many http request. For example you can set default headers and stuff. Here are the top 5 ways it differs from an HttpWebRequest which is taken from here

    1. An HttpClient instance is the place to configure extensions, set default headers, cancel outstanding requests and more.
    2. You can issue as many requests as you like through a single HttpClient instance.
    3. HttpClients are not tied to particular HTTP server or host; you can submit any HTTP request using the same HttpClient instance.
    4. You can derive from HttpClient to create specialized clients for particular sites or patterns
    5. HttpClient uses the new Task-oriented pattern for handling asynchronous requests making it dramatically easier to manage and coordinate multiple outstanding requests.

提交回复
热议问题