Пример #1
0
        /// <summary>获取客户端</summary>
        /// <returns></returns>
        protected virtual HttpClient GetClient()
        {
            if (_Client != null)
            {
                return(_Client);
            }

            // 允许宽松头部
            WebClientX.SetAllowUnsafeHeaderParsing(true);

            var asm   = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
            var agent = "";

            if (asm != null)
            {
                agent = $"{asm.GetName().Name} v{asm.GetName().Version}";
            }

            var client = new HttpClient(new HttpClientHandler {
                UseProxy = false
            });
            var headers = client.DefaultRequestHeaders;

            headers.UserAgent.ParseAdd(agent);

            return(_Client = client);
        }
Пример #2
0
        /// <summary>获取客户端</summary>
        /// <returns></returns>
        protected virtual HttpClient GetClient()
        {
            if (_Client != null)
            {
                return(_Client);
            }

            // 允许宽松头部
            WebClientX.SetAllowUnsafeHeaderParsing(true);

            var client = CreateClient();

            return(_Client = client);
        }