Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
breakoutModefull-width
languagec#
// Create a HttpClient with the certificate
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;
var httpClientHandler = new HttpClientHandler();
var certificateThumbprint = "Dit certifikat thumbprint";
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certificate = store.Certificates.Find(X509FindType.FindBySubjectName, certificateThumbprint, validOnly: false)[0];
httpClientHandler.ClientCertificates.Add(certificate);
var httpClient = new HttpClient(httpClientHandler);
// API endpoint URL
var apiUrl = "https://virksomhedsindsatst1.startest.dk/v1/Jobannonce/5832974";
// Add headers to the request
httpClient.DefaultRequestHeaders.Add("x-activeOrganisation", "{\"OrganisationType\":24,\"OrganisationCode\":\"Portal CVR\"}");
httpClient.DefaultRequestHeaders.Add("x-requestUserMetadata", "{\"RequestUserStructure\":{\"UserFullName\":\"Full Name\",\"RequestUserType\":3,\"UserIdentifier\":\" \",\"UserEmail\":\"test@test.dk\"},\"RequestOrganisationStructure\":{\"OrganisationType\":24,\"OrganisationCode\":\"Portal bruger CVR\"},\"RegistrationDateTime\":\"2023-07-12T09:41:38\"}");
try
{
	// Make a GET request with the ID parameter
	var response = await httpClient.GetAsync($"{apiUrl}");
	// Ensure the response was successful
	response.EnsureSuccessStatusCode();
	// Read the response content as JSON
	var responseContent = await response.Content.ReadAsStringAsync();
	// Deserialize the JSON response dynamically
	dynamic jsonResponse = JsonSerializer.Deserialize<dynamic>(responseContent);
	// Use the jsonResponse object as needed
	// ...
	Console.WriteLine("API call successful!");
}
catch (Exception ex)
{
	Console.WriteLine($"Error: {ex.Message}");
}

...