4
我正在構建一個代理服務器來處理本地請求。
例如 - 捕獲網絡瀏覽器打印請求並將其發送到相應的LAN打印機。
到目前爲止,我的想法是在Windows服務中託管FiddlerCore引擎。
這是我的代碼:發送HTTP到本地FiddlerCore
private static void Main()
{
FiddlerApplication.OnNotification += (sender, e) => Console.WriteLine("** NotifyUser: " + e.NotifyString);
FiddlerApplication.Log.OnLogString += (sender, e) => Console.WriteLine("** LogString: " + e.LogString);
FiddlerApplication.BeforeRequest += oSession => { Console.WriteLine("Before request for:\t" + oSession.fullUrl); oSession.bBufferResponse = true; ParseRequest(oSession); };
FiddlerApplication.BeforeResponse += oSession => Console.WriteLine("{0}:HTTP {1} for {2}", oSession.id, oSession.responseCode, oSession.fullUrl);
FiddlerApplication.AfterSessionComplete += oSession => Console.WriteLine("Finished session:\t" + oSession.fullUrl);
Console.CancelKeyPress += Console_CancelKeyPress;
Console.WriteLine("Starting FiddlerCore...");
CONFIG.IgnoreServerCertErrors = true;
FiddlerApplication.Startup(8877, true, true);
Console.WriteLine("Hit CTRL+C to end session.");
Object forever = new Object();
lock (forever)
{
Monitor.Wait(forever);
}
}
private static void ParseRequest(Session oSession)
{
switch (oSession.host)
{
case "localhost.":
Console.WriteLine("Handling local request...");
break;
}
}
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
Console.WriteLine("Shutting down...");
FiddlerApplication.Shutdown();
Thread.Sleep(750);
}
我的問題:
的ParseRequest
功能可識別本地請求(即http://localhost./print?whatever),但我怎麼可以轉發中繼他們停止代理(解析並執行打印請求,但沒有得到404頁面)?
是啊,這是正確的做法。 – EricLaw
謝謝,我看到你幫助許多人與提琴手,所以你的確認幫助我。 – toy4fun