azure-functions-host: Azure Functions v3 HttpTrigger: request body is empty
HttpTrigger works incorrectly in the following conditions:
- Azure Functions v3
- TargetFramework: netcoreapp3.1
Microsoft.NET.Sdk.Functions
version3.0.2
- Code:
[FunctionName("RunNetCore3")]
public static async Task<string> RunNetCore3Async(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "netcore3/{id}")]
CustomRouteParameter parameter,
HttpRequest request,
CancellationToken cancellationToken)
{
using (var reader = new StreamReader(request.Body, Encoding.UTF8))
{
return await reader.ReadToEndAsync();
}
}
- The request body in the
request
variable is empty if request containsContent-Type: application/json
header (works ok with any otherContent-Type
values exceptapplication/json
). So in the example the empty response body will be returned which is unexpected.
Investigative information
I’ve created the repository to demonstrate this issue. The source code of this repository is deployed to the Function App.
- Timestamp: 09:27 AM (UTC Time)
- Function App version: 3.0
- Function App name: NetCore3HttpBindingBug
- Function name(s) (as appropriate): RunNetCore3
- Invocation ID:
32894c31-74ac-4a98-8f94-fe6c76662d7d
- Region: Central US
Repro steps
- Send
POST https://netcore3httpbindingbug.azurewebsites.net/api/netcore3/qqq
request with some body andContent-Type: application/json
header.
Expected behavior
Request’s body is returned in the response.
Actual behavior
Request’s body is not returned in the response.
Known workarounds
Do not send Content-Type: application/json
header or send any other value in the Content-Type
header.
Related information
The same code works correct in Azure Functions v2 on netcoreapp2.1 with Microsoft.NET.Sdk.Functions
version 1.0.29
and in ASP.NET Core 3.1 Web Application.
There are two endpoints to check it (see the repository):
- Send
POST /netcore2/some-id
request with some body andContent-Type: application/json
header - Send
POST /aspnetcore3/some-id
request with some body andContent-Type: application/json
header
In both cases the request body will be returned in the response (I didn’t deploy it to any Function App but it’s reproducible locally as well).
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 6
- Comments: 25 (2 by maintainers)
Any word on this? Upgrading to v3 broke our microservices.
FUNCTIONS_V2_COMPATIBILITY_MODE is not doing the trick for me. You guys need to put a GIANT warning on the functions overview about this. I wasted so much time going in circles about this because I was not aware of this known issue. I am sure others have wasted time too. It is good to be more transparent about non obvious bugs like this.
Use Https instead of http with the default setup of an http trigger azure function , that worked for me