【发布时间】:2019-02-11 18:48:07
【问题描述】:
我有一个 Azure 函数,我想设置一个自定义 HTTP 端点。按照这个 SO question 的答案,我最终得到了这样的结果:
[FunctionName("DoSomething")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v1/tenants/{tenantId}/locations/{locationId}/products?manufacturer={manufacturer}")]
HttpRequest request, ILogger logger, string tenantId, string locationId, string manufacturer)
{
//
}
但是,该路由不被 Webjob 接受:
"v1/tenants/{tenantId}/locations/{locationId}/products?manufacturer={manufacturer}"
原因是因为问号'?':
创建名为“DoSomething”的路由时出错,并且 模板 'api/v1/tenants/{tenantId}/locations/{locationId}/products?manufacturer={manufacturer}'。 文字部分 'products?manufacturer=' 无效。文字部分 不能包含“?”特点。参数名称:routeTemplate 文字部分 'products?manufacturer=' 无效。文字部分 不能包含“?”字符。
问题
如何在 Azure Function 的自定义 HTTP 端点中指定查询参数?
【问题讨论】:
-
不应该是:
v1/tenants/{tenantId}/location/{locationId}/products/{productId}? -
这不是错字:)
/products?product={productId}。我想查询指定位置的潜在产品 ID,并且我想让它看起来像查询中的过滤器。我将更新问题以减少混乱... -
不,我的意思是你不应该那样做吗?这是常规方法。
-
哦...你是说我永远不应该在自定义 HTTP 端点中使用查询参数并且它应该始终是 URL 的一部分?
-
不,你可以双向,查询参数或指定它
标签: c# azure azure-functions