示例#1
0
        /// <summary>
        ///     发送GET请求。
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url">URL。</param>
        /// <param name="args">附加的参数。</param>
        /// <returns></returns>
        public static HttpResponse Get(this HttpClient client, ApiUrl url, params object[] args)
        {
            var referer = client.DefaultRequestHeaders.Referrer;

            if (url.Referer != null)
            {
                client.DefaultRequestHeaders.Referrer = new Uri(url.Referer);
            }

            var response = client.GetAsync(url.BuildUrl(args));

            response.Wait();
            // 复原client
            client.DefaultRequestHeaders.Referrer = referer;

            return(response.Result);
        }
示例#2
0
        /// <summary>
        ///     发送GET请求。
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url">URL。</param>
        /// <param name="allowAutoRedirect">允许自动重定向。</param>
        /// <param name="args">附加的参数。</param>
        /// <returns></returns>
        public static HttpResponse Get(this HttpClient client, ApiUrl url, bool?allowAutoRedirect, params object[] args)
        {
            var referer      = client.Request.Referer;
            var autoRedirect = client.Request.AllowAutoRedirect;

            client.Request.Referer = url.Referer;
            if (allowAutoRedirect.HasValue)
            {
                client.Request.AllowAutoRedirect = allowAutoRedirect.Value;
            }
            var response = client.Get(url.BuildUrl(args));

            // 复原client
            client.Request.Referer           = referer;
            client.Request.AllowAutoRedirect = autoRedirect;

            return(response);
        }