2015-09-17 69 views
0

右鍵我有以下代碼:FiddlerCore C#HTTPS事件不觸發

public partial class Form1 : Form 
{ 
    delegate void UpdateUI(); 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 

     if (!Fiddler.CertMaker.rootCertExists()) 
     { 
      if (!Fiddler.CertMaker.createRootCert()) 
      { 
       throw new Exception("Unable to create cert for FiddlerCore."); 
      } 
     } 

     if (!Fiddler.CertMaker.rootCertIsTrusted()) 
     { 
      if (!Fiddler.CertMaker.trustRootCert()) 
      { 
       throw new Exception("Unable to install FiddlerCore's cert."); 
      } 
     } 
     Fiddler.FiddlerApplication.OnNotification += delegate (object snder, NotificationEventArgs oNEA) { MessageBox.Show("** NotifyUser: " + oNEA.NotifyString); }; 
     Fiddler.FiddlerApplication.Log.OnLogString += delegate (object snder, LogEventArgs oLEA) { MessageBox.Show("** LogString: " + oLEA.LogString); }; 
     Fiddler.FiddlerApplication.AfterSessionComplete += FiddlerApplication_OnAfterSessionComplete; 
     Fiddler.FiddlerApplication.Startup(0, FiddlerCoreStartupFlags.Default & FiddlerCoreStartupFlags.DecryptSSL); 

    } 


    void FiddlerApplication_OnAfterSessionComplete(Session oSession) 
    { 
     if(oSession.fullUrl.Contains("google.com")) 
     richTextBox1.Invoke(new UpdateUI(() => 
     { 
      richTextBox1.AppendText(oSession.GetResponseBodyAsString()); 

     })); 

    } 

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
    { 
     Fiddler.FiddlerApplication.Shutdown(); 
    } 
} 

的事情是在啓動時設置DecryptSSL標誌上aftersesssion完全不閃光,我也從來沒有從任何通知得到任何消息或記錄回調。

任何想法?

回答

0

我想端口0可能是在Startup()一個問題,我試着用8888端口:

Fiddler.FiddlerApplication.Startup(8888, FiddlerCoreStartupFlags.Default & FiddlerCoreStartupFlags.DecryptSSL); 

我與這些試圖響應之前和請求處理程序,而不是OnAfterSessionComplete之前。在您的Form1_Load()

Fiddler.FiddlerApplication.BeforeRequest += new SessionStateHandler(HandleBeforeRequest); 
Fiddler.FiddlerApplication.BeforeResponse += new SessionStateHandler(HandleBeforeResponse); 

而且處理程序:

private void HandleBeforeRequest(Session oSession) 
{ 
    oSession.bBufferResponse = true; 
} 

private void HandleBeforeResponse(Session oSession) 
{ 
    if(oSession.fullUrl.Contains("google.com")) 
    { 
     richTextBox1.Invoke(new UpdateUI(() => 
     { 
      richTextBox1.AppendText(oSession.GetResponseBodyAsString()); 

     })); 
    } 
} 

順便說一句,不知道你從你的樣品省略他們,但我需要在構造函數中添加這些:

Load += Form1_Load; 
FormClosing += Form1_FormClosing; 

也可能是件好事Shutdown()之前,補充一點:

FiddlerApplication.oProxy.Detach(); 
+0

嗨亞歷克斯,謝謝你讓我試試看! –