I am trying to capture request header using fiddlercore in C#. Here is my code. I use selenium to get to the webpage for which I want to get Request header/ webforms. I am able to reach webpage but can not capture anything using fiddlercore. I know that I have to use delegate and BeginInvoke method but how exactly it should be done is unclear. I am using AfterSessionComplete event to capture request body. However it is empty. What am I missing? Can someone please help me solve this issue? Thanks. Here is my code.
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();
}
You should set Selenium to go through the FiddlerCore proxy, this is how you do it:
Advice, you can set some more flags when starting the FiddlerCore in order to save you some troubleshooting in the future:
Since you are probably using FiddlerCore + Selenium for testing, you will need to add some other stuff:
When a test finish, execute this -
Before calling FiddlerApplication.Startup(8877, fiddlerStartUpFlags);, execute these -