C# 修改webbrowser 的 useragent

简介: Also, there is a refresh option in the function (according to MSDN). It worked well for me (you should set it before any user agent change).

Also, there is a refresh option in the function (according to MSDN). It worked well for me (you should set it before any user agent change). Then the question code could be changed like this:

 

[DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
private static extern int UrlMkSetSessionOption(
    int dwOption, string pBuffer, int dwBufferLength, int dwReserved);

const int URLMON_OPTION_USERAGENT = 0x10000001;
const int URLMON_OPTION_USERAGENT_REFRESH = 0x10000002;

public void ChangeUserAgent()
{
    string ua = "Googlebot/2.1 (+http://www.google.com/bot.html)";

    UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, null, 0, 0);
    UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, ua, ua.Length, 0);
}


http://stackoverflow.com/questions/937573/changing-the-user-agent-of-the-webbrowser-control

 

目录
相关文章
|
1月前
|
JavaScript 前端开发 C#
C# webbrowser控件设置代理IP访问网站
C# webbrowser控件设置代理IP访问网站
209 5
|
C#
C#webBrowser使用代理服务器的方法winform
其实在C#中使用webBrowser大家应该都会了,论坛也有很多相前的例子大家可以查询一下就知道了但是像直接使用浏览器一样设置代理 的方法可能很多人还不知道吧。这个其实是调用一个Dll文件进行设置的,下面大家跟我一起来看看吧首先还是要先建一个结构就是代理信息的结构体如下 [C#] 纯文本查看 复制...
1440 0
|
C#
C# winform webbrowser如何指定内核为IE11? 输出 this.webbrowser.Version 显示版本是IE11的,但实际版本不是啊! 网上打的修改注册表HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet
最佳答案   1)假设你应用程序的名字为MyApplication.exe 2)运行Regedit,打开注册表,找到 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\...
2387 0
|
JavaScript C# 前端开发
c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
原文:c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 可以实现例如通过应用程序操作google搜索,用户输入要搜索的内容,然后在google中搜索;可以自动点击网页上的按钮等功能     1.
2488 0