在C#中将Httpheader添加到Selenium Chrome Webdriver [英] Add Httpheader to selenium chrome webdriver in C#
问题描述
我的C#代码类似于用于创建chrome网络驱动程序的代码,我想将自定义HTTP标头添加到我的所有http请求中.
My C# code looks like this for creating chrome web driver, i wanted to add the custom HTTP headers to all my http requests.
例如:user-agent:Android
ex: user-agent : Android
var service = ChromeDriverService.CreateDefaultService(@"c:\Chrome\");
var option = new ChromeOptions();
_driver = new ChromeDriver(service, option);
如链接所示,我们有办法使用firefox,但对于chrome则无法使用. https://eveningsamurai. wordpress.com/2013/11/21/changing-http-headers-for-a-selenium-webdriver-request/
We have the way for firefox, as the link shows, but for chrome it does not work. https://eveningsamurai.wordpress.com/2013/11/21/changing-http-headers-for-a-selenium-webdriver-request/
任何帮助表示赞赏
推荐答案
处理这种情况的一种方法是使用FiddlerCore代理,捕获所有请求并将标头修改为请求的一部分. https://www.nuget.org/packages/FiddlerCore/
One way to handle this case is with FiddlerCore proxy, capture all the requests and modify the header as part of request. https://www.nuget.org/packages/FiddlerCore/
关于Fiddler核心的不错的博客 http://weblog.west-wind.com/posts/2014/Jul/29/Using-FiddlerCore-to-capture-HTTP-Requests-with-NET
Nice blog about fiddler core http://weblog.west-wind.com/posts/2014/Jul/29/Using-FiddlerCore-to-capture-HTTP-Requests-with-NET
public static void Start()
{
FiddlerApplication.RequestHeadersAvailable += FiddlerApplication_RequestHeadersAvailable;
FiddlerApplication.Startup(8888, true, true, true);
}
static void FiddlerApplication_RequestHeadersAvailable(Session oSession)
{
oSession.RequestHeaders.Add("My_Custom_Header", "XXXXXXXXXXXXXXXX");
}
这篇关于在C#中将Httpheader添加到Selenium Chrome Webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!