use*_*284 5 azure azure-functions
刚刚开始使用 azure 函数。我将它用作 IoT 设备的 httptrigger。
我正在尝试设置一个功能,该功能适用于来自多个 IoT 设备的 httptrigger 请求 - 因此我不必为每个设备设置一个功能。所以理想情况下,在我的 c# 文件中,我会有这样的东西:
DeviceClient deviceClient;
string iotHubUri = "myhub";
string deviceName = "something dynamic here that changes with device";
string deviceKey = "something dynamic here that changes with device";
Run Code Online (Sandbox Code Playgroud)
然后,我想让我的函数 url 看起来像这样:
"https://<functionapp>.azurewebsites.net/api/<function>/{device_id}?code=xxxxx"
Run Code Online (Sandbox Code Playgroud)
其中 device_id 是 IoT 设备 ID。
我不确定如何首先将 c# 文件中的引用设置为动态,以及如何让 url 看起来像我想要的那样。
一些帮助将不胜感激。谢谢
有一个路由参数正是为此的 HTTP 触发器。您的触发器定义应如下所示:
"bindings": [
{
"type": "httpTrigger",
"route": "something/{deviceid}",
"name": "request",
// possibly other parameters
}
],
Run Code Online (Sandbox Code Playgroud)
如果您使用预编译的 C# 函数,您可以通过属性属性执行相同的操作,例如
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "GET", Route = "something/{deviceid}")]
HttpRequest request,
string deviceid)
{
// do something based on device id
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3460 次 |
| 最近记录: |