Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top