首页 > 解决方案 > HTTP 触发 azure 函数在本地不运行时出现问题

问题描述

我在 Visual Studio (C#) 中有一个基本的 HTTP 触发 azure 函数:

[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");
}

但我有两个问题:

(1) 我只希望它接收“发布”请求。但是当我从参数中取出时,"get"该函数不再接收我在 Azure 中的请求。我得到一个404 Not Found. 但在本地它仍然收到我的请求并且工作正常。

(2) 此外,Azure 中未收到请求正文。它是空的。再次在本地运行时不会出现此类问题。

我发现了几个人遇到问题的案例(2),但还没有找到解决方法。关于问题(1),目前还没有网上发布过类似的案例。

有谁知道为什么会这样?

标签: c#azureazure-functionshttprequestazure-http-trigger

解决方案


推荐阅读