namespace Client { internal class Program { static string username = "demo_user"; static string accessKey = "8370921743021"; static string secret = "321094343143"; static string baseUrl = @"https://publicapi.stage.nt.cloud.bewotec.de"; private class Content { public string Prop { get; set; } } static void Main(string[] args) { GetRequest(); PostRequest(); } static void GetRequest() { string httpVerb = "GET"; string path = "/td/travel-infos/4711"; string query = "?q=100"; Send(httpVerb, path, query, null, false); } static void PostRequest() { string httpVerb = "POST"; string path = "/td/booking-documents/1"; string query = ""; Content content = new Content { Prop = "value" }; Send(httpVerb, path, query, content, true); } static void Send(string httpVerb, string path, string query, object content, bool includePayload) { using (var client = new System.Net.Http.HttpClient()) { client.BaseAddress = new System.Uri(baseUrl + path + query); using (var request = new System.Net.Http.HttpRequestMessage()) { request.Method = new System.Net.Http.HttpMethod(httpVerb); request.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); string bodyHash = string.Empty; if (content != null) { var content_ = new System.Net.Http.StringContent(System.Text.Json.JsonSerializer.Serialize(content)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request.Content = content_; if (includePayload) { request.Headers.TryAddWithoutValidation("x-nt-content-sha256", "true"); using (var sha256Hash = System.Security.Cryptography.SHA256.Create()) { byte[] bodyBytes = content_.ReadAsByteArrayAsync().Result; var hash = sha256Hash.ComputeHash(bodyBytes); bodyHash = System.Convert.ToBase64String(hash); } } } string utcDate = System.DateTime.UtcNow.ToString("yyyyMMddHHmmss"); //20210118093334 string pathAndQueryString = path + query; string assembleUpper = string.Concat(utcDate, httpVerb.ToUpper(), pathAndQueryString.ToUpper(), bodyHash);//20210118093334GET/TD/TRAVEL-INFOS/4711?Q=100 System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); byte[] textBytes = encoding.GetBytes(assembleUpper); byte[] keyBytes = encoding.GetBytes(secret); byte[] hashBytes; using (var hash = new System.Security.Cryptography.HMACSHA256(keyBytes)) { hashBytes = hash.ComputeHash(textBytes); } string signature = System.Convert.ToBase64String(hashBytes);//C8P/6j4En8+pqLA9gcQmih7rU119s/F9iMCHZMBxPOc= string authorization = string.Format(@"DirectGrant {0} {1} {2} {3}", username, accessKey, utcDate, signature);//DirectGrant test@davincint-test.de public1234 20210118093334 C8P/6j4En8+pqLA9gcQmih7rU119s/F9iMCHZMBxPOc= request.Headers.Add("Authorization", authorization); using (var response = client.Send(request)) { } } } } } }