You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调用HTTP触发的Azure WebJob?附示例代码

正确调用HTTP触发Azure Function的方法

核心误区

你混淆了Azure WebJob和Azure Functions:你编写的代码是Azure Functions的HTTP触发器,并非传统WebJob。WebJob的scm地址仅用于管理WebJob,无法直接调用函数接口。

正确调用步骤

1. 确认正确的访问地址

函数的基础访问地址为你的App Service地址,完整路径格式为:
https://[name].[location].azurewebsites.net/api/[FunctionName]
对应你的函数,具体地址是:
https://[name].[location].azurewebsites.net/api/HttpTriggerFunction

2. 修正curl命令参数错误

你误用了-x参数(该参数用于指定代理),正确的GET请求命令应为:

curl "https://[name].[location].azurewebsites.net/api/HttpTriggerFunction?name=John"

3. 处理权限验证

你的函数设置了AuthorizationLevel.Function权限,调用时必须携带函数密钥,两种方式可选:

  • 方式一:在URL后追加code参数
curl "https://[name].[location].azurewebsites.net/api/HttpTriggerFunction?name=John&code=[你的函数密钥]"
  • 方式二:通过请求头传递密钥
curl -H "x-functions-key: [你的函数密钥]" "https://[name].[location].azurewebsites.net/api/HttpTriggerFunction?name=John"

4. 获取函数密钥的方法

  1. 登录Azure门户,找到你的Function App
  2. 进入目标HttpTriggerFunction函数页面
  3. 在右侧菜单栏选择「函数密钥」,复制默认的default密钥即可

额外说明:POST请求示例

如果需要发送POST请求,可使用以下命令:

curl -H "Content-Type: application/json" -H "x-functions-key: [你的函数密钥]" -d '{"name":"John"}' "https://[name].[location].azurewebsites.net/api/HttpTriggerFunction"

内容的提问来源于stack exchange,提问作者NEWTON MALLICK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 16:15:07