是否有可能使用的HttpBrowserCapabilities从C#控制台应用程序? [英] Is it possible to use HttpBrowserCapabilities from a c# console application?
问题描述
我需要从一个控制台应用程序解析的UserAgent字符串,这似乎是一个简单的方法来做到这一点,但我显然不具备的Htt的prequest对象,似乎不能做一个假一用一User-Agent头(我得到的平台不支持除外)。有没有办法做到这一点,或者我应该开始探索其他替代用户代理解析?
I need to parse UserAgent strings from a console app and this seems like a simple way to do it, but I obviously don't have an HttpRequest object and can't seem to make a fake one with a User-Agent header (I get platform not supported exception). Is there any way to do this, or should I start exploring other alternatives to user agent parsing?
推荐答案
的用户代理
头可以通过的HttpBrowserCapabilities $解析C $ C>类的<一的帮助href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.browsercapabilitiesfactory.aspx\">BrowserCapabilitiesFactory,如下:
The User-Agent
header can be parsed by the HttpBrowserCapabilities
class with the help of a BrowserCapabilitiesFactory, as follows:
var userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) " +
"Gecko/20100914 Firefox/3.6.10";
var browser = new HttpBrowserCapabilities {
Capabilities = new Hashtable {{string.Empty, userAgent}}
};
var factory = new BrowserCapabilitiesFactory();
factory.ConfigureBrowserCapabilities(new NameValueCollection(), browser);
这篇关于是否有可能使用的HttpBrowserCapabilities从C#控制台应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!