0

我必须使用时间触发器编写一个 azure 函数,该函数将在每个周末访问一个 API,并从该 API 获取数据并将该数据存储到我的 Azure SQL 数据库中。

所以,我不知道如何从时间触发天蓝色函数调用 API 来获取数据以及如何将这些数据存储到我的天蓝色 SQL 数据库中。

4

1 回答 1

0

您可以按照此链接开始使用 Azure 函数计时器触发器。

你必须使用HTTPClient来调用 Api。

static HttpClient client = new HttpClient();
// Update port # in the following line.
client.BaseAddress = new Uri("http://localhost:64195/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
    new MediaTypeWithQualityHeaderValue("application/json"));

Product product = null;
HttpResponseMessage response = await client.GetAsync(path);
if (response.IsSuccessStatusCode)
{
    product = await response.Content.ReadAsAsync<Product>();
}
return product;

注意:如果您必须调用大量 API/端点,可能会出现端口耗尽错误。HttpClientFactory建议用于该场景。

于 2020-03-14T11:15:33.570 回答