当我在本地 运行 我的 Azure Functions 时,为什么会收到 404?

Why am I getting a 404 when I run my Azure Function locally?

我在 C# 中设置了一个非常简单的 Azure 函数来响应 HttpTrigger。当我 运行 函数在本地跟随 Microsoft Azure instructions 时,我得到的只是一个空的 404 响应。

我正在使用 Visual Studio 2017 v15.3 Preview with the Azure Function Tools 安装的扩展程序。这是我的 Azure 函数的代码:

[FunctionName("Func1")]        
public static async Task<object> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, WebHookType = "genericJson")]
    HttpRequestMessage req, 
    TraceWriter log)
{
    return req.CreateResponse(HttpStatusCode.OK);
}

当我在本地 运行 它时(通过 right-clicking VS 项目并转到调试 > 启动新实例)它似乎启动得很好。我的函数被识别,为它给出的 URL 是 http://localhost:7071/api/Func1

但是,当我 GET 或 POST 到上面的 URL(Content-Type header 设置为 "application/json")时,我得到一个空的404响应。 Azure Functions CLI 控制台输出:

[6/12/2017 12:26:12 PM] Executing HTTP request: {

[6/12/2017 12:26:12 PM] "requestId": "ae247ea6-c055-40f5-a09c-40ea207cc785",

[6/12/2017 12:26:12 PM] "method": "GET",

[6/12/2017 12:26:12 PM] "uri": "/api/Func1"

[6/12/2017 12:26:12 PM] }

[6/12/2017 12:26:12 PM] Executed HTTP request: {

[6/12/2017 12:26:12 PM] "requestId": "ae247ea6-c055-40f5-a09c-40ea207cc785",

[6/12/2017 12:26:12 PM] "method": "GET",

[6/12/2017 12:26:12 PM] "uri": "/api/Func1",

[6/12/2017 12:26:12 PM] "authorizationLevel": "Anonymous"

[6/12/2017 12:26:12 PM] }

[6/12/2017 12:26:12 PM] Response details: {

[6/12/2017 12:26:12 PM] "requestId": "ae247ea6-c055-40f5-a09c-40ea207cc785",

[6/12/2017 12:26:12 PM] "status": "NotFound"

[6/12/2017 12:26:12 PM] }

为什么我会收到 404,我该如何解决?

您需要指定methods参数,例如

[HttpTrigger(AuthorizationLevel.Anonymous, "GET")]