POST-os hívás tesztje az authentikációhoz
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user