0

I want to send a HTTP request from my c# app and I want a properly constructed user agent string so that (at least) the operating system is well represented.

I found this:

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

that allows me to look up the correct strings for a given version of windows (my app will only run on windows), but surely I'm not expected to have a lookup table myself (what if my App ran on a new version of windows, I need to update it just to add a new UA string!

There must be some API I can call to get the UA string for the current OS, I just can't seem to find it.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
steeveeet
  • 639
  • 6
  • 25

1 Answers1

0

It's unclear what you mean by "well represented". Most browsers just report "Windows NT $NTversion".

See Detect Windows version in .net and Get OS Version / Friendly Name in C# for how to obtain the Windows version. Basically:

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
}

However, if your app runs on Windows 8 or above (8.1, 10, ...), you need to manifest your app for that version, otherwise it will return 8.0 (NT 6.2). I suppose that with a newer Windows version you'll have to re-manifest for that version as well.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272