Web浏览器导航用户代理
我正在尝试使用以下代码在我的应用程序中强制使用网络浏览器的用户代理。
webBrowser.Navigate("http://localhost/run.php", null, null, "User-Agent: Here Put The User Agent");
但是 VS 不会接受这个代码,给我错误。
方法“Navigate”没有重载需要 4 个参数
我缺少什么?
I am trying to use the follwing code to force user agent for the webbrowser in my app.
webBrowser.Navigate("http://localhost/run.php", null, null, "User-Agent: Here Put The User Agent");
However VS wont accept this code, giving me error.
No overload for method 'Navigate' takes 4 arguments
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此和this Silverlight 中不存在具有多个可用参数的
Navigate
- 所以 VS 是正确的...您显示的代码可以在 .NET 4 上运行,但不能在 .NET 4 上运行与银光。我没有在 Silverlight
WebBrowser
控件中看到设置任何标头的选项,因此我怀疑 Silverlight 无法实现您想要的功能...根据您的用例,可能可以使用WebClient 和/或 <一个href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.95%29.aspx" rel="nofollow">HttpWebRequest 来实现您的目标想要(注意这些不会渲染!)。According to this and this there is no
Navigate
with more than one parameter available in Silverlight - so VS is right... the code you show would work with .NET 4 but not with Silverlight.I don't see an option to set any header in the Silverlight
WebBrowser
control so I would suspect that what you want to is not possible with Silverlight... depending on your usecase it might be possible to use WebClient and/or HttpWebRequest to achieve what you want (BEWARE these don't render!).您可能想尝试这种方法:使用 WebClient 手动下载 HTML 内容并设置 UserAgent 标头 (webClient.Headers[ HttpRequestHeader.UserAgent ] = "my custom user agent string"),然后使用 NavigateToString 将内容设置到 WebBrowser 控件中方法。
一些标头在 Silverlight 中使用受到限制,并且在 Silverlight for Windows Phone 中具有不同的限制,并且我在这方面至少被误导过一次,所以如果不尝试并运行它,我不知道您是否对 UserAgent 具有写访问权限平台。
您可能还需要将 Accept 标头设置为“application/xhtml+xml, text/html, /”之类的值,这是 IE9 用于 Accept 标头的值; “text/html”可能就可以了;不设置 Accepts 标头也可能有效。
You might want to try this approach: download the HTML content manually using WebClient and setting the UserAgent header (webClient.Headers[ HttpRequestHeader.UserAgent ] = "my custom user agent string"), then set the content into the WebBrowser control using the NavigateToString method.
Some headers have restricted use in Silverlight, and different restrictions in Silverlight for Windows Phone, and I've been misled at least once on this score, so I don't know without trying and running it if you have write access to UserAgent on the platform.
You might also need set the Accept header to a value like "application/xhtml+xml, text/html, /" which is what IE9 uses for the Accept header; "text/html" would probably do just fine; not setting an Accepts header might work, too.