set cutom user agent in web browser control when navigating to a single page
How can I set a custom user agent for a webbrowser cont开发者_如何学Crol? The control is loading a page where I need to spoof it. I am using c sharp.
This has been asked many times on here. I suggest searching for a solution next time before posting a new question, but you can easily do this by using the WebBrowser control's Navigate() method. Just note that this will only work when you use this method, after you navigate to another page, it will "reset".
webBrowser1.Navigate("http://yoursite.com", "_self", null, "User-Agent: Custom User Agent string");
Also, other header information can be included in the header parameter as well. More information can be found here.
Microsoft's official way to customize the User Agent is to implement the IOleControl::OnAmbientPropertyChange
event to respond to DISPID_AMBIENT_USERAGENT
requests (but does not affect Navigate()
or a page's DOM), or use UrlMkSetSessionOption(URLMON_OPTION_USERAGENT)
.
精彩评论