private string getuseragent()
{
WebBrowser wb = new WebBrowser();
wb.Navigate("about:blank");
while (wb.IsBusy) Application.DoEvents();
object window = wb.Document.Window.DomWindow;
Type wt = window.GetType();
object navigator = wt.InvokeMember("navigator", BindingFlags.GetProperty,null, window, new object[] { });
Type nt = navigator.GetType();
object userAgent = nt.InvokeMember("userAgent", BindingFlags.GetProperty,null, navigator, new object[] { });
return userAgent.ToString();
}
{
WebBrowser wb = new WebBrowser();
wb.Navigate("about:blank");
while (wb.IsBusy) Application.DoEvents();
object window = wb.Document.Window.DomWindow;
Type wt = window.GetType();
object navigator = wt.InvokeMember("navigator", BindingFlags.GetProperty,null, window, new object[] { });
Type nt = navigator.GetType();
object userAgent = nt.InvokeMember("userAgent", BindingFlags.GetProperty,null, navigator, new object[] { });
return userAgent.ToString();
}
本文介绍了一种使用C#从WebBrowser控件中获取UserAgent字符串的方法。通过创建WebBrowser实例并导航到about:blank,随后利用反射机制来读取navigator对象的userAgent属性。
2173

被折叠的 条评论
为什么被折叠?



