gpt4 book ai didi

javascript - Azure Function 不通过 context.res 返回响应

转载 作者:太空宇宙 更新时间:2023-11-04 03:27:38 24 4
gpt4 key购买 nike

我正在尝试从 Azure Function 返回一个 JSON 对象,我的意思是,通过 context.res 执行响应创建根本不起作用的示例。

context.res = {
body: {"name": "JSON STATHAM"}, //No. No mistake.
contentType: 'application/json'
};

为什么?

只有通过context.done作为第二个参数传递时它才起作用。

最佳答案

查看您的 http 输出绑定(bind) name 属性是如何指定的。曾经,我们的模板/示例默认使用 $return 作为输出绑定(bind)名称。使用 $return 意味着响应应该是函数的返回值:

{
"bindings": [
{
"type": "httpTrigger",
"name": "req",
"direction": "in",
"methods": [ "get" ]
},
{
"type": "http",
"name": "$return",
"direction": "out"
}
]
}

在该模式下,仅使用通过 context.done 返回的值(即函数返回值)。将 $return 更改为您选择的其他名称,您就可以使用 context.res

关于javascript - Azure Function 不通过 context.res 返回响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42548199/

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