gpt4 book ai didi

Azure函数错误: "The Application could not be found"

转载 作者:行者123 更新时间:2023-12-03 06:10:50 27 4
gpt4 key购买 nike

下午好,

我开发了一个 Azure Function,但在 Azure 环境中运行它时,出现以下错误:{"error":{"message":"找不到应用程序","code":"ApplicationNotFoundError ","correlationId":"blabla-blabla-bla-blablablabla"}}

这是我的代码:

[FunctionName("GetOperationData")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

string id = req.Query["id"];

var applicationInsightsAppId = "blablabla-blablaba-blabla-blablalbla";
var apiKey = "thisIsMySecret";

httpClient.DefaultRequestHeaders.Add("x-api-key", apiKey);

var query = $@" requests
| where id == '{id}'
| join kind=inner (exceptions) on operation_Id
| join kind=inner (dependencies) on operation_Id
| join kind=inner (traces) on operation_Id
| project id, name, url, success, resultCode,
operation_Name, operation_Id, client_Type,
client_IP, client_City, client_StateOrProvince";


var content = new StringContent(JsonConvert.SerializeObject(new { query = query }),
Encoding.UTF8, "application/json");

var response = await httpClient.PostAsync($"https://api.applicationinsights.io/v1/apps/{applicationInsightsAppId}/query"
, content);

var responseString = await response.Content.ReadAsStringAsync();
return new OkObjectResult(responseString);
}

这是错误:

enter image description here enter image description here

我检查了所有配置,似乎一切正常,所以我的角色是贡献者。

有人可以帮我吗?

提前致谢!

最佳答案

我使用了您的代码并得到了预期的结果

代码:

using  System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;

namespace Company.Function
{
public static class TestFunction01
{
[FunctionName("GetOperationData")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

string id = req.Query["id"];

var applicationInsightsAppId = "*********";
var apiKey = "******************";

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", apiKey);

var query = $@" requests
| where id == '{id}'
| join kind=inner (exceptions) on operation_Id
| join kind=inner (dependencies) on operation_Id
| join kind=inner (traces) on operation_Id
| project id, name, url, success, resultCode,
operation_Name, operation_Id, client_Type,
client_IP, client_City, client_StateOrProvince";

var content = new StringContent(JsonConvert.SerializeObject(new { query = query }),
Encoding.UTF8, "application/json");

var response = await client.PostAsync($"https://api.applicationinsights.io/v1/apps/{applicationInsightsAppId}/query"
, content);

var responseString = await response.Content.ReadAsStringAsync();
return new OkObjectResult(responseString);
}
}
}

输出:

enter image description here

enter image description here

当我在代码中将 applicationInsightsAppId 的值更改为不正确的值时,我开始收到错误消息。

enter image description here

确保您使用正确的 applicationInsightsAppIdapiKey 值。

关于Azure函数错误: "The Application could not be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76827780/

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