This repository has been archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
64 lines (57 loc) · 2.49 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.IO;
using System.Net;
using System.Text;
namespace DumpHttpRequests
{
internal class Program
{
private static void Main(string[] args)
{
string jsonText = System.IO.File.ReadAllText(@"C:\ProgramData\SteelSeries\SteelSeries Engine 3\coreProps.json");
char[] separators = new char[] { '{', '}', ',', '"' };
string[] coreProps = jsonText.Split(separators, StringSplitOptions.RemoveEmptyEntries);
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:12345/");
listener.Start();
Console.WriteLine("Listening...");
while (true)
{
try
{
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
string ProxiedData;
using (Stream receiveStream = request.InputStream)
{
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
ProxiedData = readStream.ReadToEnd();
}
}
HttpListenerResponse response = context.Response;
string responseString = ProxiedData;
Console.WriteLine(ProxiedData);
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
System.IO.Stream output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
output.Close();
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://" + coreProps[2] + request.Url.PathAndQuery);
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(ProxiedData);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
}
catch (WebException webex)
{
Console.WriteLine(webex);
}
}
}
}
}