HttpClient vs HttpWebRequest

I have a large file that I have to send to the web api client ... Data is multi-part. The problem is that if the file is sent via an http request, it is quickly uploaded to webapi. For this request, the contents of the file are written directly through the request stream.

Where, as if the same file was sent via Httpclient (.net 4.5), the download is slow compared to the http web request. I am using multipartformdatacontent in async post HttpClient.

So, for large files we only need to use a web request? or are there any settings on Httpclient that speed up loading?

+34
asp.net-web-api
Mar 06 '14 at 4:26
source share
2 answers

HttpClient more like a browser without a header. This is a powerful and ideal tool if you intend to create many HTTP requests. For example, you can set headers and more by default. Here are the top five ways it differs from the HttpWebRequest , which is taken from here

  • The HttpClient instance is the place to configure extensions, set default headers, cancel outstanding requests, etc.
  • You can ask as many requests as you want through a single instance of HttpClient.
  • HttpClients are not tied to a specific HTTP server or host; you can send any HTTP request using the same HttpClient instance.
  • You can get HttpClient to create custom clients for specific sites or templates.
  • HttpClient uses a new task-oriented template for processing asynchronous requests, which greatly simplifies the management and coordination of several outstanding requests.
+36
Mar 06
source

I used FileStreamContent with httpclient ... But when I used ByteArrayContent, it worked fine.

I'm not sure how and why this matters, but sending bytes on a stream is a better way than sending a stream

+3
Mar 06 '14 at 18:09
source



All Articles