POST-os hívás tesztje az authentikációhoz

This commit is contained in:
2025-01-21 16:21:48 +01:00
parent 177aa668a6
commit 862f0a148b
8 changed files with 82 additions and 14 deletions
+24 -4
View File
@@ -20,10 +20,6 @@ namespace WorkFlowCheck.MAUI.Services
_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", apiKey);
}
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
@@ -50,5 +46,29 @@ namespace WorkFlowCheck.MAUI.Services
};
}
}
public async Task<ApiResponseDTO<UserDTO>> Login(string username, string password)
{
try
{
// Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/User/Login";
// HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
return response ?? new ApiResponseDTO<UserDTO>
{
IsSuccess = false,
};
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<UserDTO>
{
IsSuccess = false
};
}
}
}
}