Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure functions 本地调试Azure函数_Azure Functions - Fatal编程技术网

Azure functions 本地调试Azure函数

Azure functions 本地调试Azure函数,azure-functions,Azure Functions,我在.Net标准2.0中有一个函数: [FunctionName("A_Test")] public static async Task<string> Test(ILogger log, ExecutionContext context) { log.LogInformation("test"); return "hello"; } 我应该能够使用以下方法测试非http触发的函数: curl --request PO

我在.Net标准2.0中有一个函数:

    [FunctionName("A_Test")]
    public static async Task<string> Test(ILogger log, ExecutionContext context)
    {
        log.LogInformation("test");
        return "hello";
    }
我应该能够使用以下方法测试非http触发的函数:

curl --request POST -H "Content-Type:application/json" --data '{}' http://localhost:7071/admin/functions/A_Test -v
但是,当作为调试运行时,我得到的只是一个400错误:

[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] }

为什么?

您的函数没有任何与之关联的触发器,这可能是因为它没有被标识为触发器。例如,您可以添加计时器触发器


下面的方法/黑客可能也适用:当我有一个非HTTP触发器并希望在本地测试它时,我将实际逻辑提取到它自己的类中。然后我打开一个单独的HTTP触发器,该触发器仅用于测试

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

Azure函数需要这种主体:

{}
事实上,这是:

'{}'
解决方案是不对--data参数使用引号,如下所示:


curl--requestpost-H“Content-Type:application/json”--数据{}http://localhost:7071/admin/functions/A_Test -v

根据我上面引用的链接,它不需要触发器。这是由持久函数调用的。我可以使用管理员url调用它
'{}'