5

I'm developing a program in c# that will allow me to capture the requests made by the WebBrowser1.

My problem is that the "request data" is always empty. I don't understand where I have to put the "webBrowser1.Navigate" command.

For now my code is as follows.

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();

}

thanks for the help

Blorgbeard
  • 93,378
  • 43
  • 217
  • 263
Ldg
  • 261
  • 1
  • 7
  • 16

2 Answers2

3

What "request data" are you referring to?

The core problem here is that you're calling Startup with a false parameter, indicating that Fiddler isn't becoming the proxy for ANY process at all, so you'll never see any data unless you directly send a HTTP request to that proxy instance.

If your goal is to capture traffic from this app and this app only, call

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

after you've started the proxy instance. This will set the current process' WinINET proxy setting to point at the FiddlerCore instance you've started.

EricLaw
  • 54,427
  • 7
  • 140
  • 182
  • Now Works! Thank you so much for the answer! this line save me! URLMonInterop.SetProxyInProcess("127.0.0.1:8888", ""); – Ldg Dec 06 '12 at 10:45
0

I am guessing, but I think you need to re-arrange your code so that you set up fiddler before you make a request:

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();
}
Blorgbeard
  • 93,378
  • 43
  • 217
  • 263
  • hello! thanks for the reply, but even rearranging the code does not still works, the strange thing is that if I open fiddler2 there are requests, but if I point my application as a filter, also fiddler2 receives no request! Thank you again! – Ldg Dec 05 '12 at 08:51