Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#使用WebClient下载分块编码的内容_C#_Chunked Encoding - Fatal编程技术网

C#使用WebClient下载分块编码的内容

C#使用WebClient下载分块编码的内容,c#,chunked-encoding,C#,Chunked Encoding,我编写了一个客户端应用程序,假设它从web服务器下载一个文件,非常简单: using (WebClient webClient = new WebClient()) { webClient.DownloadFile("http://localhost/audiotest/audio.wav", @"C:\audio.wav"); } 网站(音频文件所在位置:)的标题传输编码为:chunked 当我运行程序时,出现以下错误: 服务器

我编写了一个客户端应用程序,假设它从web服务器下载一个文件,非常简单:

using (WebClient webClient = new WebClient())
{
    webClient.DownloadFile("http://localhost/audiotest/audio.wav", 
                           @"C:\audio.wav");
}
网站(音频文件所在位置:)的标题传输编码为:chunked

当我运行程序时,出现以下错误:

服务器违反了协议。节=响应体 Detail=响应区块格式无效


当服务器包含传输编码:分块标头时,如何下载文件?

我还没有尝试过,但这可能会起作用:

如果您强制发送对Http 1.0而不是Http 1.1的请求,则服务器将以 指定内容长度的HTTP头

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://localhost/audiotest/audio.wav");
wr.ProtocolVersion = Version.Parse("1.0"); 

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
您将在
response.GetResponseStream()中以流的形式获取文件

这一切都归功于这本书的作者