我正在使用 .NET Core 3.1 开发 ASP.NET Web 应用程序。该应用程序从具有错误的外部网络服务器下载 mp3 文件:响应标头中的 Content-Length 报告的字节数高于 mp3 的实际字节数。
这是使用 curl 从该服务器下载文件的示例:
curl -sSL -D - "http://example.com/test.mp3" -o /dev/null
HTTP/1.1 200 OK
Cache-Control: private
Pragma: no-cache
Content-Length: 50561024
Content-Type: audio/mpeg
Content-Range: bytes 0-50561023/50561024
Expires: 0
Accept-Ranges: 0-50561023
Server: Microsoft-IIS/10.0
Content-Transfer-Encoding: binary
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 03 Jan 2020 23:43:54 GMT
curl: (18) transfer closed with 266240 bytes remaining to read
Run Code Online (Sandbox Code Playgroud)
因此,即使 curl 报告传输不完整,mp3 也完全下载了 50294784 字节,我可以在我尝试过的任何音频播放器中打开它。
我在我的 Web 应用程序中想要的是与 curl 相同的行为:忽略不正确的 Content-Length 并下载 …