Azure 函数未通过 context.res 返回响应
Azure Function not returning response through context.res
我正在尝试 return 来自 Azure Function 的 JSON 对象,这个例子,我的意思是,响应创建通过 context.res 根本不工作。
context.res = {
body: {"name": "JSON STATHAM"}, //No. No mistake.
contentType: 'application/json'
};
为什么?
只有通过 context.done 如果作为第二个参数传递它才有效。
查看您的 http 输出绑定 name
属性 是如何指定的。有一次我们的 templates/samples 默认使用 $return
作为输出绑定名称。使用 $return
意味着响应应该是函数 :
的 return 值
{
"bindings": [
{
"type": "httpTrigger",
"name": "req",
"direction": "in",
"methods": [ "get" ]
},
{
"type": "http",
"name": "$return",
"direction": "out"
}
]
}
在该模式下,将仅使用通过 context.done
编辑的值 return(即函数 return 值)。将 $return
更改为您选择的其他名称,您可以使用 context.res
.
我正在尝试 return 来自 Azure Function 的 JSON 对象,这个例子,我的意思是,响应创建通过 context.res 根本不工作。
context.res = {
body: {"name": "JSON STATHAM"}, //No. No mistake.
contentType: 'application/json'
};
为什么?
只有通过 context.done 如果作为第二个参数传递它才有效。
查看您的 http 输出绑定 name
属性 是如何指定的。有一次我们的 templates/samples 默认使用 $return
作为输出绑定名称。使用 $return
意味着响应应该是函数 :
{
"bindings": [
{
"type": "httpTrigger",
"name": "req",
"direction": "in",
"methods": [ "get" ]
},
{
"type": "http",
"name": "$return",
"direction": "out"
}
]
}
在该模式下,将仅使用通过 context.done
编辑的值 return(即函数 return 值)。将 $return
更改为您选择的其他名称,您可以使用 context.res
.