如何在C#中使用Fiddlercore捕获http请求?
我正在尝试使用C#中的fiddlercore捕获请求头。这是我的密码。我使用selenium访问要获取其请求头/webforms的网页。我可以访问网页,但无法使用fiddlercore捕获任何内容。我知道我必须使用delegate和BeginInvoke方法,但具体应该如何做还不清楚。 我正在使用AfterSessionComplete事件捕获请求正文。然而,它是空的。我错过了什么?有人能帮我解决这个问题吗?谢谢这是我的密码如何在C#中使用Fiddlercore捕获http请求?,c#,selenium,fiddlercore,C#,Selenium,Fiddlercore,我正在尝试使用C#中的fiddlercore捕获请求头。这是我的密码。我使用selenium访问要获取其请求头/webforms的网页。我可以访问网页,但无法使用fiddlercore捕获任何内容。我知道我必须使用delegate和BeginInvoke方法,但具体应该如何做还不清楚。 我正在使用AfterSessionComplete事件捕获请求正文。然而,它是空的。我错过了什么?有人能帮我解决这个问题吗?谢谢这是我的密码 public void requestURL() {
public void requestURL()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com");
IWebElement query = driver.FindElement(By.Name("q"));
// search Cheese
query.SendKeys("Cheese");
//// submit query
query.Submit();
// Wait for the page to load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.StartsWith("Cheese"); });
// Should see: "Cheese - Google Search"
Console.WriteLine("Page title is: " + driver.Title);
Console.WriteLine("URL for page is: " + driver.Url);
}
static void Main(string[] args)
{
FiddlerApplication.Startup(8877, FiddlerCoreStartupFlags.DecryptSSL);
HttpActions h = new HttpActions();
h.requestURL();
FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
FiddlerApplication.Shutdown();
}
static void FiddlerApplication_AfterSessionComplete(Session oSession)
{
var s = oSession.GetRequestBodyAsString();
}
var seleniumProxy = new Proxy { HttpProxy = "localhost:8878", SslProxy = "localhost:8878" };
var profile = new FirefoxProfile();
profile.SetProxyPreferences(seleniumProxy);
var slenium = new FirefoxDriver(profile);
const FiddlerCoreStartupFlags fiddlerStartUpFlags = FiddlerCoreStartupFlags.DecryptSSL & FiddlerCoreStartupFlags.AllowRemoteClients & FiddlerCoreStartupFlags.CaptureFTP & FiddlerCoreStartupFlags.ChainToUpstreamGateway & FiddlerCoreStartupFlags.MonitorAllConnections & FiddlerCoreStartupFlags.CaptureLocalhostTraffic;
FiddlerApplication.Startup(8877, fiddlerStartUpFlags);
FiddlerApplication.oProxy.PurgeServerPipePool();//Run this between tests to make sure the new test will start "clean"
在调用FiddlerApplication.Startup(8877,fiddlerStartUpFlags)之前;,执行这些命令—
FiddlerApplication.Prefs.SetStringPref("fiddler.config.path.makecert", @"d:\..\Makecert.exe");//To define the MakeCert.exe path manually.
FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);//Abort session when client abort
Jim Evans是与Selenium相关的开发人员之一,他在这里详细介绍了它: