Skip to content

[System.Net.Http.Json] HttpClient not always calling HttpContent.LoadIntoBufferAsync #46683

@danielgerlag

Description

@danielgerlag

Description

When doing a Post with HttpClient and using JsonContent, I noticed that sometimes an empty body is posted. When I drilled into it, I found that if I explicitly call LoadIntoBufferAsync() on the HttpContent then the issue goes away and everything works fine.

var content = JsonContent.Create(data);
await content.LoadIntoBufferAsync();  //without this, it doesn't always work
await _httpClient.PostAsync(item.CallBack, content);

Configuration

.net core 3.1
System.Net.Http.Json, Version=5.0.0.0

Hosted on Azure App Service, with AppInsights enabled

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions