首页 新闻 会员 周边 捐助

.NET Core 中如何通过 HttpClient 发送 chunked requests

1
悬赏园豆:30 [已解决问题] 解决于 2018-08-30 23:06

请问 .NET Core 中如何通过 HttpClient 发送 chunked requests ?对应的请求头是 Transfer-Encoding: chunked

dudu的主页 dudu | 高人七级 | 园豆:31030
提问于:2018-08-29 09:03
< >
分享
最佳答案
0

搞定!

using (var httpClient = new HttpClient())
{
    httpClient.DefaultRequestHeaders.TransferEncodingChunked = true;
    using (var ms = new MemoryStream())
    {
        var streamContent = new StreamContent(ms);
        for (int i = 0; i < 100; i++)
        {
            var bytes = Encoding.UTF8.GetBytes("Hello World!");
            ms.Write(bytes);
            ms.Flush();

            var response = await httpClient.PostAsync(uri, streamContent);
            Console.WriteLine($"Requested {response.RequestMessage.RequestUri}...{response.StatusCode}");
        }
    }
}
dudu | 高人七级 |园豆:31030 | 2018-08-30 23:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册