UWP 設置 UserAgent 值,如下操作:
using System.Runtime.InteropServices;
class UserAgentHelper
{
[DllImport("urlmon.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
private static extern int UrlMkSetSessionOption(int dwOption, string pBuffer, int dwBufferLength, int dwReserved);
private const int URLMON_OPTION_USERAGENT = 0x10000001;
public static void SetDefaultUserAgent(string userAgent)
{
UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, userAgent, userAgent.Length, 0);
}
}