// using System.Net.Http;
// using System.Net.Http.Headers;
// using System.Text;
// using System.Text.Json;
static async Task<string> LoginAsync(HttpClient http, string email, string password) {
var content = new FormUrlEncodedContent(new Dictionary<string,string> {
["user_mail"] = email, ["password"] = password
});
var res = await http.PostAsync("https://<domaine>/abf_api/login.php", content);
res.EnsureSuccessStatusCode();
using var s = await res.Content.ReadAsStreamAsync();
using var doc = await JsonDocument.ParseAsync(s);
return doc.RootElement.GetProperty("token").GetString();
}
static async Task<JsonDocument> GetPlanAsync(HttpClient http, string token, int pilotId) {
var req = new HttpRequestMessage(HttpMethod.Get, $"https://<domaine>/abf_api/plan-get.php?pilote_id={pilotId}");
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
var res = await http.SendAsync(req);
res.EnsureSuccessStatusCode();
return JsonDocument.Parse(await res.Content.ReadAsStringAsync());
}
static async Task PushUpdateAsync(HttpClient http, string token, object payload) {
var json = JsonSerializer.Serialize(payload);
var req = new HttpRequestMessage(HttpMethod.Post, "https://<domaine>/abf_api/tracker-update.php");
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
req.Content = new StringContent(json, Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
res.EnsureSuccessStatusCode();
}
// Usage (exemple)
var http = new HttpClient();
var token = await LoginAsync(http, "[email protected]", "MotDePasse");
var plan = await GetPlanAsync(http, token, 1);
// TODO: parser plan.RootElement.GetProperty("data") …
await PushUpdateAsync(http, token, new {
pilot_id = 1, ac_id = 179357, number = "ABF4053", departure = "LIRF", arrival = "LICC",
flightstate = "enroute", lat = 41.799, lon = 12.246, altitude = 32000, ground_speed = 450,
heading = 145, timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
});