// MaverickHttpPush.exe — conversa HTTP com o servico local do GfnSdk. // O 501 vem de um dispatcher HTTP simples que aceita metodos GET/POST/headers (Connection: Close). // Aqui: envia requisicoes reais, mostra resposta crua, e testa rotas do gfnsdk. // csc /nologo /optimize+ /out:MaverickHttpPush.exe MaverickHttpPush.cs // MaverickHttpPush.exe --port 48010 using System; using System.IO; using System.Net.Sockets; using System.Text; internal static class MaverickHttpPush { static string Raw(string host, int port, string request, int waitMs) { try { using (var c = new TcpClient()) { var t = c.ConnectAsync(host, port); if (!t.Wait(1500) || !c.Connected) return "(nao conectou)"; using (var s = c.GetStream()) { byte[] data = Encoding.ASCII.GetBytes(request); s.Write(data, 0, data.Length); s.Flush(); var sb = new StringBuilder(); var buf = new byte[8192]; var end = DateTime.UtcNow.AddMilliseconds(waitMs); while (DateTime.UtcNow < end) { try { var r = s.ReadAsync(buf, 0, buf.Length); if (!r.Wait(400)) continue; int n = r.Result; if (n <= 0) break; sb.Append(Encoding.ASCII.GetString(buf, 0, n)); if (sb.Length > 4000) break; } catch { break; } } return sb.Length == 0 ? "(sem resposta)" : sb.ToString(); } } } catch (Exception ex) { return "(erro) " + ex.GetType().Name + " " + ex.Message; } } static string Get(string host, int port, string path, string extraHeaders = "") { var sb = new StringBuilder(); sb.Append("GET ").Append(path).Append(" HTTP/1.1\r\n"); sb.Append("Host: ").Append(host).Append(':').Append(port).Append("\r\n"); sb.Append("User-Agent: MaverickHttpPush\r\n"); sb.Append("Accept: */*\r\n"); sb.Append("Connection: close\r\n"); if (!string.IsNullOrEmpty(extraHeaders)) sb.Append(extraHeaders); sb.Append("\r\n"); return sb.ToString(); } static string Post(string host, int port, string path, string body) { var sb = new StringBuilder(); sb.Append("POST ").Append(path).Append(" HTTP/1.1\r\n"); sb.Append("Host: ").Append(host).Append(':').Append(port).Append("\r\n"); sb.Append("User-Agent: MaverickHttpPush\r\n"); sb.Append("Content-Type: application/json\r\n"); sb.Append("Content-Length: ").Append(Encoding.UTF8.GetByteCount(body)).Append("\r\n"); sb.Append("Connection: close\r\n\r\n"); sb.Append(body); return sb.ToString(); } static void Show(string label, string reply) { Console.WriteLine("--> " + label); string[] lines = reply.Split('\n'); int shown = 0; foreach (string line in lines) { string clean = line.TrimEnd('\r'); if (clean.Length == 0) continue; Console.WriteLine(" " + clean); if (++shown >= 10) { Console.WriteLine(" ..."); break; } } Console.WriteLine(); } static int Main(string[] args) { int port = 48010; string host = "127.0.0.1"; for (int i = 0; i < args.Length; i++) if (args[i] == "--port" && i + 1 < args.Length) int.TryParse(args[++i], out port); Console.WriteLine("=== MaverickHttpPush ==="); Console.WriteLine("user=" + Environment.UserName + " session=" + System.Diagnostics.Process.GetCurrentProcess().SessionId); Console.WriteLine("alvo " + host + ":" + port + "\n"); string[] paths = { "/", "/index.html", "/ping", "/status", "/health", "/AppInfo/v.1.0/ping", "/AppInfo/v.1.0/Notification", "/SDK/v.1.0/BusMessage", "/EventAPI/v.1.0/BusMessage", }; foreach (string p in paths) Show("GET " + p, Raw(host, port, Get(host, port, p), 2000)); string notif = "{\"method\":\"POST\",\"url\":\"rtsp://Serenity/AppInfo/v.1.0/Notification\",\"event\":\"process\",\"action\":2,\"processId\":1,\"processName\":\"probe\"}"; Show("POST /AppInfo/v.1.0/Notification", Raw(host, port, Post(host, port, "/AppInfo/v.1.0/Notification", notif), 2500)); Show("POST /v1/message", Raw(host, port, Post(host, port, "/v1/message", "{}"), 2000)); // HEAD e TRACE — alguns dispatchers respondem diferente e vazam Allow: Show("TRACE /", Raw(host, port, "TRACE / HTTP/1.1\r\nHost: " + host + ":" + port + "\r\nConnection: close\r\n\r\n", 2000)); return 0; } }