将参数从逻辑应用程序电子邮件触发器传递到 azure 函数 http 触发器问题
pass parameters from logic app email trigger to azure function http trigger issue
我有一个 azure logic 应用程序,它在出现电子邮件时触发,然后我将其链接到 http 触发的 azure 函数。我正在尝试读取从逻辑应用程序传递的函数中的一些参数。谁能告诉我我做错了什么。
天蓝色函数中的代码
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string attachmentName = req.Query["attachmentName"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
name 被正确填充,但 attachmentName 被忽略。我认为这与最后一行代码有关。 data.name。我不明白那条线在做什么。
根据测试,req.Query
以<your-url>? parameter1 = value1¶meter2 = value2
的形式获取参数。也就是说,req.Query
只能获取到Get
请求中的参数。
您正在发送 post 请求,因此使用 req.Query
无法获取您想要的参数。
I think it has something to do with the last line of code. data.name. I don't understand what that line is doing.
这段代码是判断name是否为空,如果为空则name=data?name.
req.Query
没有获取name的值,所以这段代码从data?.name
获取name的值,所以这就是为什么name
有值但是attachmentName
在您的结果中没有任何价值。
正确的代码应该是这样的:
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string attachmentName = req.Query["attachmentName"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
attachmentName = attachmentName ?? data?.attachmentName;
log.LogInformation(name);
log.LogInformation(attachmentName);
return new OkObjectResult(name);
}
}
我有一个 azure logic 应用程序,它在出现电子邮件时触发,然后我将其链接到 http 触发的 azure 函数。我正在尝试读取从逻辑应用程序传递的函数中的一些参数。谁能告诉我我做错了什么。
天蓝色函数中的代码
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string attachmentName = req.Query["attachmentName"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
name 被正确填充,但 attachmentName 被忽略。我认为这与最后一行代码有关。 data.name。我不明白那条线在做什么。
根据测试,req.Query
以<your-url>? parameter1 = value1¶meter2 = value2
的形式获取参数。也就是说,req.Query
只能获取到Get
请求中的参数。
您正在发送 post 请求,因此使用 req.Query
无法获取您想要的参数。
I think it has something to do with the last line of code. data.name. I don't understand what that line is doing.
这段代码是判断name是否为空,如果为空则name=data?name.
req.Query
没有获取name的值,所以这段代码从data?.name
获取name的值,所以这就是为什么name
有值但是attachmentName
在您的结果中没有任何价值。
正确的代码应该是这样的:
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string attachmentName = req.Query["attachmentName"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
attachmentName = attachmentName ?? data?.attachmentName;
log.LogInformation(name);
log.LogInformation(attachmentName);
return new OkObjectResult(name);
}
}