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

 

目录
相关文章
|
9月前
|
JavaScript 前端开发 C#
C# webbrowser控件设置代理IP访问网站
C# webbrowser控件设置代理IP访问网站
459 5
|
JavaScript C# 前端开发
c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
原文:c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 可以实现例如通过应用程序操作google搜索,用户输入要搜索的内容,然后在google中搜索;可以自动点击网页上的按钮等功能     1.
2569 0
c# WebBrowser 操作
使用:http://wenku.baidu.com/view/511d37faf705cc17552709d4.html  (含验证码,点击等) 用法 :http://wenku.baidu.com/view/4efa281a6bd97f192279e9f0.html
494 0
|
Web App开发 C#
C# WinForm WebBrowser 设置为编辑模式
写个程序批量下载文件,要分析的HTML的页面是需要登录才能访问的,而下载的相关页面是不需要登录访问的,所以偷个懒,程序中把WebBrowser 设置为编辑模式,这样把要分析的内容从已经登录的浏览器窗口中复制过来就可以了。
793 0