简体   繁体   English

Web浏览器导航用户代理

[英]Webbrowser navigate user agent

I am trying to use the follwing code to force user agent for the webbrowser in my app. 我正在尝试使用以下代码在我的应用中强制使用Web浏览器的用户代理。

webBrowser.Navigate("http://localhost/run.php", null, null, "User-Agent: Here Put The User Agent");

However VS wont accept this code, giving me error. 但是,VS不会接受此代码,这给了我错误。

No overload for method 'Navigate' takes 4 arguments 方法“ Navigate”的不重载采用4个参数

What am I missing? 我想念什么?

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. 根据这个这个有没有Navigate与Silverlight中提供了多个参数-所以VS是正确的...你展示的代码将在.NET 4中,但不与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!). 我没有看到在Silverlight WebBrowser控件中设置任何标头的选项,因此我怀疑Silverlight无法实现您想要的...根据您的用例,可能可以使用WebClient和/或HttpWebRequest来实现您想要什么(请注意,这些不会渲染!)。

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. 您可能想尝试这种方法:使用WebClient手动下载HTML内容并设置UserAgent标头(webClient.Headers [HttpRequestHeader.UserAgent] =“我的自定义用户代理字符串”),然后使用NavigateToString将内容设置到WebBrowser控件中方法。

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. 某些标头在Silverlight中限制了使用,在Windows Phone的Silverlight中有不同的限制,并且在此分数上,我至少被误导了一次,因此,如果您拥有对UserAgent的写访问权,那么我不知道是否要尝试并运行它平台。

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; 您可能还需要将Accept标头设置为“ application / xhtml + xml,text / html, / ”之类的值,这是IE9用于Accept标头的; "text/html" would probably do just fine; “ text / html”可能很好。 not setting an Accepts header might work, too. 不设置Accepts标头也可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM