英文:
azure http trigger works fine locally, loads fine on cloud, throws error when given params
问题
I see that you want a Chinese translation of the provided text. Here's the translation:
这应该是一件容易的事情:
我有这个HTTP触发器:
public static class Function1
{
[FunctionName("httphook")]
// def link: localhost:7070/api/httphook?function=webhook&data=this_could_be_your_data
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
string function = req.Query["function"];
if (function == "webhook")
{
// do the webhook
string data = req.Query["data"];
return new OkObjectResult("ja");
}
else
{
return new OkObjectResult("error");
}
}
}
当我在本地运行它并打开此链接时:
localhost:7070/api/httphook?function=webhook
我得到了 "ja"。
现在我使用VS将其上传到Azure(所有设置都是默认的,并且所有设置都是通过VS的GUI设置的)
并且页面在这里加载:
https://webhookcircles.azurewebsites.net
当您点击链接时,您将轻松看到页面上写着 "it works fine"。
现在给出最终链接
https://webhookcircles.azurewebsites.net/api/httphook?function=webhook
它返回:401页面不起作用。
有人可以告诉我为什么吗?
英文:
This should be an easy thing:
I have this http trigger:
public static class Function1
{
[FunctionName("httphook")]
// def link: localhost:7070/api/httphook?function=webhook&data=this_could_be_your_data
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
string function = req.Query["function"];
if (function == "webhook")
{
// do the webhook
string data = req.Query["data"];
return new OkObjectResult("ja");
}
else
{
return new OkObjectResult("error");
}
}
}
When I run it locally and open this linK:
localhost:7070/api/httphook?function=webhook
I am being returned "ja".
Now I use VS to upload this to azure (all settings are default, and all is set up from the gui in vs)
and the page loads here:
https://webhookcircles.azurewebsites.net
When you click the link, youll easily see that the page says "it works fine".
Now giving it the final link
https://webhookcircles.azurewebsites.net/api/httphook?function=webhook
It returns: 401 page doenst work.
Can someone tell me why?
答案1
得分: 0
在将您的函数发布到Azure后,您需要使用函数密钥来访问URL,因为您正在使用AuthorizationLevel.Function
。
您可以按照下面所示的方式复制URL
或者您可以从下面获取函数密钥
现在您的URL将如下所示
https://webhookcircles.azurewebsites.net/api/httphook?code=<function key here>&function=webhook
Output:
英文:
After publishing your function to azure, you need to use the function key in order to access the URL, as you are using AuthorizationLevel.Function
You can copy the URL as shown below
or you can get the function key from below
Now your URL will look like
https://webhookcircles.azurewebsites.net/api/httphook?code=<function key here>&function=webhook
Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论