This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1761|Reply: 4

[ASP.NET] ASP.NET Core (thirty) HtpClient streams, outputs responses while downloading

[Copy link]
Posted on 2024-12-13 19:20:39 | | | |
Requirements: ASP.NET Core project, the download interface is to download data responses from other sites to users, similar to the function of a reverse proxy. Using HttpClient to download files and simultaneously respond to output (i.e., streaming) is a common need, especially when dealing with large files. This avoids loading entire files into memory, improving performance and resource utilization. At the same time, it will also shorten the browser response time and will not keep the browser spinning in circles.

HtpClient does not use streaming, downloads resources to content and then responds to users, as shown in the following image:



Users have to wait 26 seconds for the browser to receive a response and start downloading the file, which is a very bad user experience.

HtpClient uses streaming, and users only need to wait 1 second to start downloading content (the waiting time depends on the bandwidth of the website server or the target resource server), as shown in the figure below:



The code is as follows:

(End)





Previous:Windows uses tar to compress and package folders
Next:Perform a diagnostic test on memory with Memtest86 Pro v11
 Landlord| Posted on 2024-12-13 19:21:15 |
Java oss Alibaba Cloud upload file settings download file name
https://www.itsvse.com/thread-7853-1-1.html
 Landlord| Posted on 2024-12-13 21:33:47 |
Fix the bug that caused the program to be abnormal when the user actively canceled, entered the exception, and modified the response status code "System.InvalidOperationException: StatusCode cannot be set because the response has already started", and other bug fixes, the code is as follows:






 Landlord| Posted on 2024-12-13 21:42:04 |
You can find a few large files to test:https://mirrors.aliyun.com/centos/7/isos/x86_64/
 Landlord| Posted on 2025-5-13 16:40:08 |
Little slag Posted on 2024-12-13 21:33
Fix the user actively cancels, enters the exception, and modifies the response status code "System.InvalidOperationException: StatusCode canno...

repairInvalid non-ASCII or control character in header: 0x000Dabnormal

Code:

The hyperlink login is visible.-> SetContentDispositionHeader method
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com