From b7f769c0866877ac3f153504bcb8d5c18bd1ca2f Mon Sep 17 00:00:00 2001 From: russell Date: Wed, 1 May 2024 16:40:45 +0400 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20APIClient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TravelAgency/TravelAgencyWebApp/APIClient.cs | 49 ------------------- TravelAgency/TravelAgencyWebApp/Program.cs | 2 - .../TravelAgencyWebApp/appsettings.json | 4 +- 3 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 TravelAgency/TravelAgencyWebApp/APIClient.cs diff --git a/TravelAgency/TravelAgencyWebApp/APIClient.cs b/TravelAgency/TravelAgencyWebApp/APIClient.cs deleted file mode 100644 index 45bbfe9..0000000 --- a/TravelAgency/TravelAgencyWebApp/APIClient.cs +++ /dev/null @@ -1,49 +0,0 @@ -using TravelAgencyContracts.ViewModels; -using Newtonsoft.Json; -using System.Net.Http.Headers; -using System.Text; - -namespace TravelAgencyClientApp -{ - public class APIClient - { - private static readonly HttpClient _client = new(); - - public static UserViewModel? User { get; set; } = null; - - public static void Connect(IConfiguration configuration) - { - _client.BaseAddress = new Uri(configuration["IPAddress"]); - _client.DefaultRequestHeaders.Accept.Clear(); - _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - } - - public static T? GetRequest(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } - } - - public static void PostRequest(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); - - var response = _client.PostAsync(requestUrl, data); - - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - } -} \ No newline at end of file diff --git a/TravelAgency/TravelAgencyWebApp/Program.cs b/TravelAgency/TravelAgencyWebApp/Program.cs index 868cdaa..0f3ee13 100644 --- a/TravelAgency/TravelAgencyWebApp/Program.cs +++ b/TravelAgency/TravelAgencyWebApp/Program.cs @@ -1,9 +1,7 @@ -using TravelAgencyClientApp; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); -APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { diff --git a/TravelAgency/TravelAgencyWebApp/appsettings.json b/TravelAgency/TravelAgencyWebApp/appsettings.json index cf0ea09..10f68b8 100644 --- a/TravelAgency/TravelAgencyWebApp/appsettings.json +++ b/TravelAgency/TravelAgencyWebApp/appsettings.json @@ -5,7 +5,5 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*", - - "IPAddress": "http://localhost:5088/" + "AllowedHosts": "*" }