From a7ce33dd5fabff492352e16abe07610e5617be93 Mon Sep 17 00:00:00 2001 From: wanggaofeng <15601716045@163.com> Date: Tue, 21 May 2024 19:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CallApiController.cs | 22 +++++++++++++ .../HttpClientStudy.WebClient.csproj | 20 ++++++++++++ .../HttpClientStudy.WebClient.http | 6 ++++ HttpClientStudy.WebClient/Program.cs | 23 ++++++++++++++ .../Properties/launchSettings.json | 31 +++++++++++++++++++ .../appsettings.Development.json | 8 +++++ HttpClientStudy.WebClient/appsettings.json | 9 ++++++ HttpClientStudy.sln | 8 ++++- 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 HttpClientStudy.WebClient/Controllers/CallApiController.cs create mode 100644 HttpClientStudy.WebClient/HttpClientStudy.WebClient.csproj create mode 100644 HttpClientStudy.WebClient/HttpClientStudy.WebClient.http create mode 100644 HttpClientStudy.WebClient/Program.cs create mode 100644 HttpClientStudy.WebClient/Properties/launchSettings.json create mode 100644 HttpClientStudy.WebClient/appsettings.Development.json create mode 100644 HttpClientStudy.WebClient/appsettings.json diff --git a/HttpClientStudy.WebClient/Controllers/CallApiController.cs b/HttpClientStudy.WebClient/Controllers/CallApiController.cs new file mode 100644 index 0000000..79bb06e --- /dev/null +++ b/HttpClientStudy.WebClient/Controllers/CallApiController.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HttpClientStudy.WebClient.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CallApiController : ControllerBase + { + private readonly ILogger _logger; + public CallApiController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IActionResult Ping() + { + return Ok("ping"); + } + } +} diff --git a/HttpClientStudy.WebClient/HttpClientStudy.WebClient.csproj b/HttpClientStudy.WebClient/HttpClientStudy.WebClient.csproj new file mode 100644 index 0000000..397261a --- /dev/null +++ b/HttpClientStudy.WebClient/HttpClientStudy.WebClient.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + diff --git a/HttpClientStudy.WebClient/HttpClientStudy.WebClient.http b/HttpClientStudy.WebClient/HttpClientStudy.WebClient.http new file mode 100644 index 0000000..948a755 --- /dev/null +++ b/HttpClientStudy.WebClient/HttpClientStudy.WebClient.http @@ -0,0 +1,6 @@ +@HttpClientStudy.WebClient_HostAddress = http://localhost:5188 + +GET {{HttpClientStudy.WebClient_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/HttpClientStudy.WebClient/Program.cs b/HttpClientStudy.WebClient/Program.cs new file mode 100644 index 0000000..df2434c --- /dev/null +++ b/HttpClientStudy.WebClient/Program.cs @@ -0,0 +1,23 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/HttpClientStudy.WebClient/Properties/launchSettings.json b/HttpClientStudy.WebClient/Properties/launchSettings.json new file mode 100644 index 0000000..d7baba9 --- /dev/null +++ b/HttpClientStudy.WebClient/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:52546", + "sslPort": 0 + } + }, + "profiles": { + "WebClient": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5188", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/HttpClientStudy.WebClient/appsettings.Development.json b/HttpClientStudy.WebClient/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/HttpClientStudy.WebClient/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/HttpClientStudy.WebClient/appsettings.json b/HttpClientStudy.WebClient/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/HttpClientStudy.WebClient/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/HttpClientStudy.sln b/HttpClientStudy.sln index 35dd6d2..5398fd0 100644 --- a/HttpClientStudy.sln +++ b/HttpClientStudy.sln @@ -18,7 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{56D9132E-6 Docs\说明.md = Docs\说明.md EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClientStudy.Config", "HttpClientStudy.Config\HttpClientStudy.Config.csproj", "{78FCC8F1-C196-4D4F-81A0-D0A1E0843AAE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientStudy.Config", "HttpClientStudy.Config\HttpClientStudy.Config.csproj", "{78FCC8F1-C196-4D4F-81A0-D0A1E0843AAE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClientStudy.WebClient", "HttpClientStudy.WebClient\HttpClientStudy.WebClient.csproj", "{40EFD636-C7A1-4AB1-A364-E044FBF9CF50}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -50,6 +52,10 @@ Global {78FCC8F1-C196-4D4F-81A0-D0A1E0843AAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {78FCC8F1-C196-4D4F-81A0-D0A1E0843AAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {78FCC8F1-C196-4D4F-81A0-D0A1E0843AAE}.Release|Any CPU.Build.0 = Release|Any CPU + {40EFD636-C7A1-4AB1-A364-E044FBF9CF50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40EFD636-C7A1-4AB1-A364-E044FBF9CF50}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40EFD636-C7A1-4AB1-A364-E044FBF9CF50}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40EFD636-C7A1-4AB1-A364-E044FBF9CF50}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE