问题描述
我写的是假设从Web服务器下载文件,很简单的客户端应用程序:
I wrote a client application that is suppose to download a file from a web server, very simple:
using (WebClient webClient = new WebClient())
{
webClient.DownloadFile("http://localhost/audiotest/audio.wav",
@"C:\audio.wav");
}
该网站(如音频文件位于:)有头传输编码:分块
The web site (where audio file located: http://localhost/audiotest/audio.wav) has header Transfer-Encoding: chunked
当我运行程序时,我收到以下错误:
When I run the program, I get following error:
服务器犯了违反协议。第= ResponseBody
细节=响应块格式无效
我如何下载时服务器包含传输编码的文件: ?分块标题
How can I download the file when server contains Transfer-Encoding: chunked header?
推荐答案
我还没有尝试过,但是这可能工作:
I haven't tried it but this might work:
如果您强制发送一个请求HTTP 1.0而不是HTTP 1.1,然后服务器将用
HTTP标头指定的Content-Length回复
If you forcefully send an request for Http 1.0 rather than Http 1.1 then server will reply with HTTP Header specifying Content-Length
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://localhost/audiotest/audio.wav");
wr.ProtocolVersion = Version.Parse("1.0");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
您将获得 response.GetResponseStream的文件流()
所有信贷的
这篇关于使用Web客户端下载C#分块编码的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!