I have a basic HTTP trigger azure function in Visual Studio (C#):
[FunctionName("HttpTriggerCSharp")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
But I'm having 2 issues with this:
(1) I only want it to receive 'Post' requests. But when I take out the "get"
from the arguments the function no longer receives my requests in Azure. I get a 404 Not Found
. But locally it stills receives my request and works fine.
(2) Additionally the body of the request is not received in Azure. Its empty. Once again when running locally no such problems occur.
I found several cases of people having the issue (2), but haven't found a way to solve. As to issue (1), haven't found any similar cases posted online yet.
Does anyone have any idea on why this is happening?