请问 .NET Core 中如何通过 HttpClient 发送 chunked requests ?对应的请求头是 Transfer-Encoding: chunked
搞定!
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}");
}
}
}