gpt4 book ai didi

javascript - Azure Functions [Node.js] : context. BindingData 不包含我的路由参数(如文档所示)

转载 作者:行者123 更新时间:2023-12-03 03:47:14 26 4
gpt4 key购买 nike

我目前正在构建一个应该检索 2 个路由参数的函数(第一个是必需的,第二个是可选的),但尽管遵循了他们的文档,我还是遇到了一些问题。

具体来说,我正在关注this一些说明,但不幸的是它不会按预期工作。

在我的 function.json 中,我有以下代码:

{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"name": "req",
"direction": "in",
"methods": [ "get" ],
"route": "MyFunction/{courseId:alpha}/{locale:alpha?}"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}

说明告诉我可以在 context.bindingData 上访问这两个参数,但它没有出现。我(此时)访问信息的唯一方法是分割路径(存在于 context.bindingData.path 上)。不过,我真的不喜欢这个解决方案,尤其是当文档告诉我们另一种方法时。

这里是context.bindingData里面的内容:

{
"invocationId": "1067e7e5-f85f-481c-8605-645cf78dcb25",
"path": "MyFunction/windscreen/en",
"query": {

},
"headers": {
"cache-Control": "max-age=0",
"connection": "keep-alive",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-Encoding": "gzip,deflate,br",
"accept-Language": "da-DK,da;q=0.9,en-US;q=0.8,en;q=0.7,la;q=0.6,nb;q=0.5",
"host": "localhost",
"user-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",
"upgrade-Insecure-Requests": "1",
"content-Length": "0",
"sec-ch-ua": "\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\"",
"sec-ch-ua-mobile": "?0",
"sec-Fetch-Site": "none",
"sec-Fetch-Mode": "navigate",
"sec-Fetch-User": "?1",
"sec-Fetch-Dest": "document",
"x-Forwarded-For": "127.0.0.1"
},
"sys": {
"methodName": "MyFunction",
"utcNow": "2021-08-05T13:56:43.800Z",
"randGuid": "[Censored]"
}
}

提前致谢!

最佳答案

请从 here 升级到最新的 Azure Functions 核心工具看看您是否仍然看到这种行为。

我使用了3.0.3477版本,无法重现它。作为引用,所使用的出价信息与您所拥有的类似,如下所示:

 {
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [ "get" ],
"route": "MyFunc/{firstParam:alpha}/{optionalParam:alpha?}"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}

使用的网址:/api/MyFunc/FirstValue/OptionalValue

上下文.绑定(bind)数据:screenshot of context.bindingData

关于javascript - Azure Functions [Node.js] : context. BindingData 不包含我的路由参数(如文档所示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68668087/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com