Azure Webjobs SDK:HttpTrigger。本地主机上的默认 URL 是什么?

msl*_*lot 6 azure azure-webjobssdk

我有这个功能


    public class Functions
    {
        public Functions()
        {

        }

        [FunctionName("httptriggertest")]
        public async Task<IActionResult> HttpTriggerTest([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "httptriggertest")] HttpRequest req,
            ILogger log)
        {
            log.Log(LogLevel.Information, "Received request request");

            return new OkObjectResult("HttpTriggerTest");
        }
    }

Run Code Online (Sandbox Code Playgroud)

并通过以下方式运行它:

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebJobs(b =>
                {
                    b.AddAzureStorageCoreServices()
                        .AddAzureStorage()
                        .AddHttp();
                })
                .ConfigureLogging((context, b) =>
                {
                    b.SetMinimumLevel(LogLevel.Debug);
                    b.AddConsole();
                })
                .ConfigureAppConfiguration(b =>
                {
                    b.AddCommandLine(args);
                })
                .UseConsoleLifetime();
    }

Run Code Online (Sandbox Code Playgroud)

当我运行时dotnet run它启动正常(该函数由运行时发现)

info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
      Starting JobHost
info: Host.Startup[0]
      Found the following functions:
      Functions.Functions.HttpTriggerTest

info: Host.Startup[0]
      Job host started
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/mslot/git/sut_test/job1
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
      Hosting started
^Cinfo: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...
dbug: Microsoft.Extensions.Hosting.Internal.Host[3]
      Hosting stopping
info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
      Stopping JobHost
info: Host.Startup[0]
      Stopping the listener 'Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider+HttpTriggerBinding+NullListener' for function 'httptriggertest'
info: Host.Startup[0]
      Stopped the listener 'Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider+HttpTriggerBinding+NullListener' for function 'httptriggertest'
info: Host.Startup[0]
      Job host stopped
dbug: Microsoft.Extensions.Hosting.Internal.Host[4]
      Hosting stopped
Run Code Online (Sandbox Code Playgroud)

但是这个的 URL 是什么?这甚至可以在 localhost 上调用 http 端点吗?我尝试过 http://localhost/ 的各种变体

San*_*ado 0

右键单击您的 Azure Functions 项目。转到属性。选择调试。在应用程序参数下提供以下命令。

host start --port 7073 --pause-on-error
Run Code Online (Sandbox Code Playgroud)

您可以提供您喜欢的任何端口号。保存更改。再次运行您的函数应用程序。它将打开一个控制台窗口。几分钟后,它将显示您的所有本地主机端点 URL。