C
C# (.NET)
Section Guide
Modern HttpClient implementation.
`DsiClient.cs`
csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
public class DsiClient {
private static readonly HttpClient client = new HttpClient();
private const string BaseUrl = "https://fake-api.devsecit.com/1.0.0/wb/";
private const string AppToken = "PgcQqi8ZGmlnYwd50JKo74_secure_token_2024";
public async Task CallApi(string method, string table, Dictionary extraData = null) {
var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(AppToken));
var ts = Convert.ToBase64String(Encoding.UTF8.GetBytes(DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()));
var payload = new Dictionary {
{ "token", token },
{ "timestmp", ts },
{ "method", method },
{ "table", table }
};
if (extraData != null) foreach (var kv in extraData) payload[kv.Key] = kv.Value;
var content = new FormUrlEncodedContent(payload);
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_SECRET");
var response = await client.PostAsync(BaseUrl, content);
return await response.Content.ReadAsStringAsync();
}
}