Azure 函数 HttpTrigger,未在属性中使用 HttpMethods 类 [英] Azure functions HttpTrigger, not using HttpMethods class in attribute
本文介绍了Azure 函数 HttpTrigger,未在属性中使用 HttpMethods 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 AzureFunctions 中的函数需要使用
Why do functions in AzureFunctions requires to use
[HttpTrigger(AuthorizationLeve.Anonymous, "get")]
代替
[HttpTrigger(AuthorizationLeve.Anonymous, HttpMethods.Get)]
当然不能用
HttpMethods.Get.ToString()
因为语言不允许在属性中调用函数
becase language does not allow to call functions in Attributes
并创建我自己的
public static class HttpMethodsStrings
{
public const string Get = "get";
}
似乎是多余的,因为 .NET 已经提供了 HttpMethods.
seems redundant since .NET already provides HttpMethods.
推荐答案
您可以使用 System.Net.WebRequestMethods.Http.X
常量代替硬编码字符串(get"、;后").我已经把这段代码放在一起并调试了它,它工作正常.相同的片段如下所示 -
You can use System.Net.WebRequestMethods.Http.X
constants instead of hard coded strings ("get", "post"). I have put together the piece of code and debugged it and it works fine.
The snippet of the same is shown below -
这篇关于Azure 函数 HttpTrigger,未在属性中使用 HttpMethods 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文