Mobilról működik a hívás https-en :)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using WorkFlowCheck.BL.DTO;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.MAUI.Services;
|
||||
namespace WorkFlowCheck.MAUI
|
||||
{
|
||||
@@ -33,7 +33,7 @@ namespace WorkFlowCheck.MAUI
|
||||
{
|
||||
try
|
||||
{
|
||||
WelcomeLabel.Text = response.Data.Name;
|
||||
WelcomeLabel.Text = response.Data.FirstName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -11,19 +11,34 @@ namespace WorkFlowCheck.MAUI
|
||||
public static MauiApp CreateMauiApp()
|
||||
{
|
||||
var builder = MauiApp.CreateBuilder();
|
||||
|
||||
|
||||
// appsettings.json beállítása
|
||||
|
||||
string jsonFilePath = Path.Combine(FileSystem.AppDataDirectory, "appsettings.json");
|
||||
|
||||
// Másold a fájlt a Raw erőforrásokból az AppDataDirectory-ba, ha még nincs ott
|
||||
if (!File.Exists(jsonFilePath))
|
||||
{
|
||||
using var stream = FileSystem.OpenAppPackageFileAsync("appsettings.json").Result;
|
||||
using var reader = new StreamReader(stream);
|
||||
File.WriteAllText(jsonFilePath, reader.ReadToEnd());
|
||||
}
|
||||
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(FileSystem.AppDataDirectory) // A konfigurációs fájl betöltése az alkalmazás adat könyvtárából
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
builder.Services.AddSingleton<IConfiguration>(configuration);
|
||||
|
||||
builder.Services.AddHttpClient<UserService>(client =>
|
||||
{
|
||||
var apiUrl = configuration["ApiBaseUrl"]; // API-cím betöltése a konfigurációból
|
||||
client.BaseAddress = new Uri(apiUrl);
|
||||
});
|
||||
|
||||
builder.Services.AddSingleton<IConfiguration>(configuration);
|
||||
builder.Services.AddSingleton<IUserService, UserService>();
|
||||
|
||||
|
||||
builder
|
||||
.UseMauiApp<App>()
|
||||
.ConfigureFonts(fonts =>
|
||||
@@ -33,10 +48,10 @@ namespace WorkFlowCheck.MAUI
|
||||
});
|
||||
|
||||
#if DEBUG
|
||||
builder.Logging.AddDebug();
|
||||
builder.Logging.AddDebug();
|
||||
#endif
|
||||
// HttpClient regisztrálása az alap API-címmel
|
||||
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"ApiBaseUrl": "https://localhost:5069",
|
||||
"ApiBaseUrl": "https://wfcapi.nuvolar.hu/",
|
||||
"ApiKey": "RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU="
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.BL.DTO;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.BL.DTO;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
@@ -17,19 +17,21 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
_httpClient = httpClient;
|
||||
|
||||
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
|
||||
_httpClient.BaseAddress = new Uri("https://192.168.50.128:5069");
|
||||
_httpClient.BaseAddress = new Uri(apiBaseUrl);
|
||||
|
||||
var apiKey = configuration["ApiKey"];
|
||||
|
||||
// Alapértelmezett fejléc beállítása az API-kulccsal
|
||||
//_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
|
||||
// Ha egyéni fejlécet használsz:
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", "RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU=");
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
||||
}
|
||||
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Az API végpont meghatározása
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User";
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/1";
|
||||
|
||||
// HTTP GET kérés küldése
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Plugin.NFC\Plugin.NFC.csproj" />
|
||||
<ProjectReference Include="..\WorkFlowCheck.BL\WorkFlowCheck.BL.csproj" />
|
||||
<ProjectReference Include="..\WorkFlowCheck.Common\WorkFlowCheck.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user