The following code in BlazorTest is failing when a content header (such as Content-Type) is present on the request. This is preventing testing POST / PUT requests:
foreach (var header in request.Headers)
{
requestMessage.Headers.Add(header.Key, header.Value);
}
The following works, but feels a bit of a bodge:
foreach (var header in request.Headers)
{
if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value))
{
// Populate content headers if they are not added to request headers
requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value);
}
}
I've also got this working a bit more elegantly by maintaining a collection of known content headers to use for conditional population.
The following code in BlazorTest is failing when a content header (such as
Content-Type
) is present on the request. This is preventing testing POST / PUT requests:The following works, but feels a bit of a bodge:
I've also got this working a bit more elegantly by maintaining a collection of known content headers to use for conditional population.