You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建接收2个参数并返回拼接结果的HTTP Trigger Azure Function遇错求助

解决PowerShell Azure Function中"No input binding defined for the parameter 'res'"错误

问题根源

在PowerShell版Azure Function中,输出绑定的参数不需要在param块中声明。你将$res写入param($req, $res),系统会默认把它当作输入绑定去查找对应的配置,但res实际是输出绑定,因此触发错误。

修正方案

只需要修改run.ps1,移除param中的$res参数,直接输出符合HttpResponseContext格式的响应内容即可,function.json配置无需改动。

修正后的run.ps1代码

using namespace System.Net

param($req)

# 获取URL查询参数
$name1 = $req.Query.name1
$name2 = $req.Query.name2

# 拼接响应内容
$responseBody = "$name1 $name2"

# 直接输出响应到输出绑定
[HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body       = $responseBody
}

原理说明

PowerShell Azure Function的输出绑定是通过脚本的输出结果来传递的:只要你的输出结构符合对应绑定的要求(这里是HttpResponseContext类型的哈希表),系统会自动将其关联到function.json中定义的res输出绑定上,不需要提前声明参数。

内容的提问来源于stack exchange,提问作者SeanNeedsHelp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 06:30:34