Is it possible to use HttpBrowserCapabilities from a c# console application?
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 HttpReques开发者_开发百科t 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?
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);
精彩评论