SoFunction
Updated on 2025-03-07

Implementation code for intercepting Http requests


public class HttpServer : IDisposable
{
private HttpListener listener;
public void Start()
{
listener = new HttpListener();
("http://localhost/");
= | ;
();
(GetContext, null);
}
private void GetContext(IAsyncResult ar)
{
HttpListenerRequest Request;
HttpListenerResponse Response;
try
{
HttpListenerContext ctx = (ar);
Request = ;
Response = ;
//setup waiting for the next request
(GetContext, null);
}
catch (InvalidOperationException)
{
return;
}
catch (HttpListenerException)
{
return;
}
try
{
var sw = new StreamWriter();
(@"<html><body><p>Your request has been intercepted</p></body></html>");
();
}
finally
{
();
();
}
}
public void Dispose()
{
if (listener != null)
();
}
}