【问题标题】:How to get the Windows version to include in a UserAgent string如何让 Windows 版本包含在 UserAgent 字符串中
【发布时间】:2015-08-11 08:59:09
【问题描述】:

我想从我的 c# 应用程序发送一个 HTTP 请求,并且我想要一个正确构造的用户代理字符串,以便(至少)很好地表示操作系统。

我发现了这个:

https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#PltToken

这允许我为给定版本的 windows 查找正确的字符串(我的应用程序只能在 windows 上运行),但我自己肯定不会有一个查找表(如果我的应用程序在新的windows版本,我需要更新它只是为了添加一个新的UA字符串!

我必须调用一些 API 来获取当前操作系统的 UA 字符串,但我似乎找不到它。

【问题讨论】:

    标签: c# .net http http-headers user-agent


    【解决方案1】:

    不清楚您所说的“表现良好”是什么意思。 Most browsers 只报告“Windows NT $NTversion”。

    请参阅Detect Windows version in .netGet OS Version / Friendly Name in C#,了解如何获取 Windows 版本。基本上:

    string versionString = "Unknown OS Version";
    
    var osVersion = System.Environment.OSVersion;
    if (osVersion.Platform == PlatformID.Win32NT)
    {
        versionString = string.Format("Windows NT {0}.{1}", 
                                      osVersion.Version.Major, 
                                      osVersion.Version.Minor); 
    }
    else
    {
        // handle non-NT Windows
    }
    

    但是,如果您的应用在 Windows 8 或更高版本(8.1、10、...)上运行,则需要 manifest your app for that version,否则将返回 8.0(NT 6.2)。我想对于较新的 Windows 版本,您也必须重新显示该版本。

    【讨论】:

      猜你喜欢
      • 2011-08-03
      • 1970-01-01
      • 2013-11-12
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      • 2022-11-25
      • 2012-06-12
      • 1970-01-01
      相关资源
      最近更新 更多