gpt4 book ai didi

c# - 通过 URL 请求将参数传递给 azure 持久函数

转载 作者:行者123 更新时间:2023-12-05 02:41:31 25 4
gpt4 key购买 nike

我有基本的持久功能代码:

namespace dotNetDurableFunction
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
var outputs = new List<string>();
string name = context.GetInput<string>();

// Replace "hello" with the name of your Durable Activity Function.
outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", name));

return outputs;
}

[FunctionName("Function1_Hello")]
public static string SayHello([ActivityTrigger] string name, ILogger log)
{
log.LogInformation($"Saying hello to {name}.");
return $"Hello {name}!";
}

[FunctionName("Function1_HttpStart")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
//var name = await req.Content.ReadAsStringAsync();
var name = "Bart";
log.LogInformation(name);
// Function input comes from the request content.
string instanceId = await starter.StartNewAsync("Function1", name);

log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

return starter.CreateCheckStatusResponse(req, instanceId);
}
}
}

我想要实现的是通过传递参数name来调用http触发器,如下所示:http://localhost:7071/api/Function1_HttpStart?name=Josh

然后将参数从http触发器传递到orchestrator,最后传递到orchestrator调用的事件。

现在在此代码中,输出为 Saying hello to . 因此看起来它没有通过代码传递参数,或者没有从请求 URL 中读取参数。

有什么办法可以实现这一点吗?

最佳答案

您可以使用以下代码来接收名称:

    var name = req.RequestUri.Query.Split("=")[1];

以下代码用于接收post请求中的请求体,无法接收get请求中的参数。

    var content = req.Content;
string jsonContent = content.ReadAsStringAsync().Result;

关于c# - 通过 URL 请求将参数传递给 azure 持久函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68074451/

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