using System; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; using CheatScanner.Models; namespace CheatScanner.Services; public static class ReportUploader { private static readonly HttpClient _http = new() { Timeout = TimeSpan.FromSeconds(30), }; public static async Task<(bool Success, string Message)> UploadAsync(string url, ScanReport report) { var json = JsonSerializer.Serialize(report, new JsonSerializerOptions { WriteIndented = false }); var content = new StringContent(json, Encoding.UTF8, "application/json"); try { var response = await _http.PostAsync(url, content); var body = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) return (true, "Report submitted successfully."); return (false, $"Server returned {(int)response.StatusCode}: {body.Trim()}"); } catch (TaskCanceledException) { return (false, "Request timed out."); } catch (Exception ex) { return (false, ex.Message); } } }