我正在用c#开发一个程序,它允许我捕获WebBrowser1发出的请求.
我的问题是“请求数据”始终为空.我不明白我在哪里放“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(); }
谢谢您的帮助
解决方法
您指的是什么“请求数据”?
这里的核心问题是你使用false参数调用Startup,表明Fiddler根本没有成为任何进程的代理,所以除非你直接向该代理实例发送HTTP请求,否则你永远不会看到任何数据.
如果您的目标是仅从此应用和此应用捕获流量,请致电
URLMonInterop.SetProxyInProcess(“127.0.0.1:8888”,“< -loopback>”);
在您启动代理实例之后.这会将当前进程的’WinINET代理设置设置为指向您已启动的FiddlerCore实例.