是否有可能使用的HttpBrowserCapabilities从C#控制台应用程序? [英] Is it possible to use HttpBrowserCapabilities from a c# console application?

查看:310
本文介绍了是否有可能使用的HttpBrowserCapabilities从C#控制台应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从一个控制台应用程序解析的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 类的<​​一的帮助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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆