Azure App Service WebJob httpclient getasync 请求返回 500 内部服务器错误

Azure App Service WebJob httpclient getasync request returning 500 internal server error

我有一个网络作业,它由排队的存储触发,并在收到新消息时进行网络 api 调用。我在 fiddler 中测试了 get 请求并且它有效,但是当通过 webjob 中的 httpclient getasync 发出请求时会出现 500 内部服务器错误。可以在网络作业中调用网络 api 吗?

I tested the get request in fiddler and it works, but gets 500 internal server error when the request is made via httpclient getasync within the webjob.

据我所知,500 内部服务器错误是由您的 Web API 服务器端抛出的。请尝试在您的 Web API 应用程序中使用 try-catch 包装您的代码并找到详细的错误。

Can a call to a web api be made within a webjob?

您可以在 WebJob 中发送 http 请求。这是我的代码示例,它可以在我这边和 Azure 上运行良好,您可以参考它。

Functions.cs

// This function will get triggered/executed when a new message is written 
// on an Azure Queue called queue.
public static async void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
    log.WriteLine(message);
    string requestUrl = "https://bruce-chen-001.azurewebsites.net/api/values";
    HttpClient client = new HttpClient();
    var response = await client.GetAsync(requestUrl);
    log.WriteLine("response:{0}", await response.Content.ReadAsStringAsync());
}

结果

response:["value1","value2"]