在本地调试Azure功能 [英] Debug Azure Functions locally

查看:118
本文介绍了在本地调试Azure功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.Net标准2.0中具有功能:

I have a function in .Net standard 2.0:

    [FunctionName("A_Test")]
    public static async Task<string> Test(ILogger log, ExecutionContext context)
    {
        log.LogInformation("test");
        return "hello";
    }

根据本文: https://docs.microsoft.com/zh-CN/azure/azure-functions/functions-run-local 部分非HTTP触发的函数"

according to this article: https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local section "Non-HTTP triggered functions"

对于HTTP触发器和Webhooks以外的所有其他功能,您可以通过调用管理端点在本地测试您的功能.在本地服务器上使用HTTP POST请求调用此端点会触发该功能.您可以选择传递测试数据到POST请求正文中的执行.此功能类似于Azure门户中的测试"选项卡.

"For all kinds of functions other than HTTP triggers and webhooks, you can test your functions locally by calling an administration endpoint. Calling this endpoint with an HTTP POST request on the local server triggers the function. You can optionally pass test data to the execution in the body of the POST request. This functionality is similar to the Test tab in the Azure portal.

您调用以下管理员端点来触发非HTTP功能:"

You call the following administrator endpoint to trigger non-HTTP functions:"

 http://localhost:{port}/admin/functions/{function_name}

我应该能够使用以下方法测试非HTTP触发的功能:

I should be able to test non-http triggered functions by using:

curl --request POST -H "Content-Type:application/json" --data '{}' http://localhost:7071/admin/functions/A_Test -v

但是,当以调试方式运行时,我得到的只是一个400错误:

However when running as debug, all I get is a 400 error:

[08/03/2019 12:59:08] Host lock lease acquired by instance ID '000000000000000000000000BED482F9'.
[08/03/2019 12:59:09] Executing HTTP request: {
[08/03/2019 12:59:09]   "requestId": "6dba82a1-65bf-4e10-bcc2-1e7ecdb3524c",
[08/03/2019 12:59:09]   "method": "POST",
[08/03/2019 12:59:09]   "uri": "/admin/functions/A_Test"
[08/03/2019 12:59:09] }
[08/03/2019 12:59:10] Executed HTTP request: {
[08/03/2019 12:59:10]   "requestId": "6dba82a1-65bf-4e10-bcc2-1e7ecdb3524c",
[08/03/2019 12:59:10]   "method": "POST",
[08/03/2019 12:59:10]   "uri": "/admin/functions/A_Test",
[08/03/2019 12:59:10]   "identities": [
[08/03/2019 12:59:10]     {
[08/03/2019 12:59:10]       "type": "WebJobsAuthLevel",
[08/03/2019 12:59:10]       "level": "Admin"
[08/03/2019 12:59:10]     },
[08/03/2019 12:59:10]     {
[08/03/2019 12:59:10]       "type": "WebJobsAuthLevel",
[08/03/2019 12:59:10]       "level": "Admin"
[08/03/2019 12:59:10]     }
[08/03/2019 12:59:10]   ],
[08/03/2019 12:59:10]   "status": 400,
[08/03/2019 12:59:10]   "duration": 614
[08/03/2019 12:59:10] }

为什么?

推荐答案

这里的问题是curl在POST请求的实际正文中包含了--data '{}'的引号.

The problem here is that curl includes the quotes from --data '{}' in the actual body of the POST request.

Azure函数期望这种身体:

Azure function expects this kind of body:

{}

实际上,curl发送此消息:

And in reality curl sends this:

'{}'

解决方案是不对--data参数使用引号,例如:

The solution is not to use quotes for the --data argument like so:

curl --request POST -H "Content-Type:application/json" --data {} http://localhost:7071/admin/functions/A_Test -v

这篇关于在本地调试Azure功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆