Пример #1
0
        /// <summary>
        /// Clients the HTTP get string.
        /// </summary>
        /// <typeparam name="Query">The type of the uery.</typeparam>
        /// <param name="paramstr">The paramstr.</param>
        /// <param name="customURL">The custom URL.</param>
        /// <param name="isawait">if set to <c>true</c> [isawait].</param>
        /// <returns></returns>
        public async Task <string> ClientHTTPGetString <Query>(string querystring, string customURL, bool isawait) where Query : new()
        {
            string entityname = typeof(Query).Name;

            entityname = entityname.Substring(0, entityname.IndexOf("Dto"));

            string routingUrl = string.Empty;

            if (string.IsNullOrEmpty(customURL))
            {
                routingUrl = string.Format("api/{0}/{1}", entityname, querystring);
            }
            else
            {
                routingUrl = string.Format("api/{0}/{1}?{2}", entityname, customURL, querystring);
            }

            routingUrl += "&" + VerifyTransactionSN.GenerateRandomInt();

            HttpResponseMessage response = await client.GetAsync(routingUrl).ConfigureAwait(isawait);


            string results = string.Empty;

            if (response.IsSuccessStatusCode)
            {
                results = response.Content.ReadAsStringAsync().Result;
            }
            return(results);
        }
        /// <summary>
        /// Clients the HTTP get list.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="Query">The type of the uery.</typeparam>
        /// <param name="partialURI">The partial URI.</param>
        /// <param name="isawait">if set to <c>true</c> [isawait].</param>
        /// <returns></returns>
        public async Task <TResult> ClientHTTPGetList <TResult, Query>(string partialURI, bool isawait, bool enableRandomNumber)
            where TResult : new()
        {
            using (var client = new HttpClient())
            {
                this.CreateHttpHeader(client);

                string entityname = GetAPIControllerName <Query>();

                string routingUrl = string.Format("api/{0}/{1}/?", entityname, partialURI);

                if (enableRandomNumber)
                {
                    routingUrl += VerifyTransactionSN.GenerateRandomInt();
                }

                HttpResponseMessage response = await client.GetAsync(routingUrl).ConfigureAwait(isawait);

                log.DebugFormat("请求URL:{0}  结果:{1}", client.BaseAddress + routingUrl, response.IsSuccessStatusCode);

                var results = new TResult();
                results = await ReadAsObject(response, results);

                return(results);
            }
        }
Пример #3
0
        /// <summary>
        /// Clients the HTTP get list.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="Query">The type of the uery.</typeparam>
        /// <param name="partialURI">The partial URI.</param>
        /// <param name="isawait">if set to <c>true</c> [isawait].</param>
        /// <returns></returns>
        public async Task <TResult> ClientHTTPGetList <TResult, Query>(string partialURI, bool isawait, bool enableRandomNumber)
            where TResult : new()
        {
            string entityname = GetAPIControllerName <Query>();

            string routingUrl = string.Format("api/{0}/{1}/?", entityname, partialURI);

            if (enableRandomNumber)
            {
                routingUrl += VerifyTransactionSN.GenerateRandomInt();
            }

            HttpResponseMessage response = await client.GetAsync(routingUrl).ConfigureAwait(isawait);

            var results = new TResult();

            results = await ReadAsObject(response, results);

            return(results);
        }