Azure Http 触发器函数调用
Azure Http Triggers function calls
我想要一个 Http Trigger 函数调用另一个 Http Trigger 函数。
基本上,我试图通过 URL (HTTP 请求)访问触发器 1,触发器 1 将调用触发器 2。
我的想法是为 Trigger 2 修复 URL,因此您只需调用 Trigger 1。
有什么想法吗?
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
非常感谢任何帮助。
您可以使用 HttpClient
进行普通的 HTTP 请求。调用函数可能如下所示:
static HttpClient client = new HttpClient();
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req)
{
var url = "https://<functionapp>.azurewebsites.net/api/Function2?code=<code>";
var response = await client.GetAsync(url);
string result = await response.Content.ReadAsStringAsync();
return req.CreateResponse(HttpStatusCode.OK, "Function 1 " + result);
}
我认为您应该改用 Durable Functions:
public static async Task<object> Run(DurableOrchestrationContext ctx)
{
var x = await ctx.CallActivityAsync<object>("YourOtherFunctionName");
// Rest of Function code
}
这对我有用
var url ="azure function URL with code and params";
using var client = new HttpClient();
client.GetAsync(url).Wait();
我想要一个 Http Trigger 函数调用另一个 Http Trigger 函数。 基本上,我试图通过 URL (HTTP 请求)访问触发器 1,触发器 1 将调用触发器 2。 我的想法是为 Trigger 2 修复 URL,因此您只需调用 Trigger 1。 有什么想法吗?
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
非常感谢任何帮助。
您可以使用 HttpClient
进行普通的 HTTP 请求。调用函数可能如下所示:
static HttpClient client = new HttpClient();
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req)
{
var url = "https://<functionapp>.azurewebsites.net/api/Function2?code=<code>";
var response = await client.GetAsync(url);
string result = await response.Content.ReadAsStringAsync();
return req.CreateResponse(HttpStatusCode.OK, "Function 1 " + result);
}
我认为您应该改用 Durable Functions:
public static async Task<object> Run(DurableOrchestrationContext ctx)
{
var x = await ctx.CallActivityAsync<object>("YourOtherFunctionName");
// Rest of Function code
}
这对我有用
var url ="azure function URL with code and params";
using var client = new HttpClient();
client.GetAsync(url).Wait();