2012-12-05 28 views
5

我正在開發一個程序,它將允許我捕獲WebBrowser1發出的請求。如何使用FiddlerCore捕獲數據?

我的問題是「請求數據」總是空的。我不明白我必須放置「webBrowser1.Navigate」命令。

現在我的代碼如下。

private void button3_Click(object sender, EventArgs e) 
{ 
    webBrowser1.ScriptErrorsSuppressed = true; 
    WebProxy myProxy = new WebProxy(); 
    Uri newUri = new Uri("http://localhost:8888"); 
    myProxy.Address = newUri; 

    Fiddler.FiddlerApplication.Startup(8888, false, false); 

    List<Fiddler.Session> oAllSessions = new List<Fiddler.Session>(); 

    webBrowser1.Navigate("http://www.youtube.com/"); 
    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) 
    { 
     System.Windows.Forms.Application.DoEvents(); 
    } 

    Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS) 
    { 
     Monitor.Enter(oAllSessions); 
     oAllSessions.Add(oS); 
     Monitor.Exit(oAllSessions); 
    }; 

    var message = string.Join(Environment.NewLine, oAllSessions); 
    MessageBox.Show(message); 

    Fiddler.FiddlerApplication.Shutdown(); 

} 

感謝您的幫助

+0

您的具體問題是什麼? – Blorgbeard

+0

嗨,我的問題是,「請求數據」總是空的。我不明白我必須放置「webBrowser1.Navigate」命令。再次感謝 – Ldg

回答

3

你指的是什麼「請求數據」?

這裏的核心問題是,我們在調用啓動參數,表明提琴手不會成爲代理的任何進程可言,所以你永遠不會直接看到任何數據,除非你向該代理實例發送HTTP請求。

如果你的目標是從這個應用,並且只有這個程序捕獲的流量,來電

URLMonInterop.SetProxyInProcess("127.0.0.1:8888", "<-loopback>");

你已經開始代理實例之後。這會將當前進程的WinINET代理設置設置爲指向您已啓動的FiddlerCore實例。

+0

現在的作品!非常感謝你的回答!這條線救了我! URLMonInterop.SetProxyInProcess(「127.0.0.1:8888」,「<-loopback>」); – Ldg

0

我猜,但我認爲你需要讓你設置重新安排你的代碼之前提琴手你提出一個要求:

Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS) 
{ 
    Monitor.Enter(oAllSessions); 
    oAllSessions.Add(oS); 
    Monitor.Exit(oAllSessions); 
}; 

webBrowser1.Navigate("http://www.youtube.com/"); 
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) 
{ 
    System.Windows.Forms.Application.DoEvents(); 
} 
+0

你好!感謝您的回覆,但即使重新排列代碼仍然不起作用,奇怪的是,如果我打開fiddler2有請求,但如果我將我的應用程序指向過濾器,fiddler2也不會收到請求!再次感謝你! – Ldg

+0

好的,現在fiddler2應用程序可以工作,但在c#中無事可做! – Ldg