【发布时间】:2014-08-28 05:43:02
【问题描述】:
我正在尝试在 C# 中使用 fiddlercore 捕获请求标头。这是我的代码。我使用 selenium 访问我想要获取请求标头/网络表单的网页。我可以访问网页,但无法使用 fiddlercore 捕获任何内容。我知道我必须使用委托和 BeginInvoke 方法,但具体应该如何完成尚不清楚。 我正在使用 AfterSessionComplete 事件来捕获请求正文。然而它是空的。我错过了什么?有人可以帮我解决这个问题吗?谢谢。这是我的代码。
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();
}
【问题讨论】:
-
Jim Evans 是 Selenium 的开发者之一,他在这里广泛地介绍了它:jimevansmusic.blogspot.co.uk
标签: c# selenium fiddlercore