コード例 #1
0
        /// <summary>
        /// 使用服务发现获取host
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="discovery"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public static T For <T>(IServiceDiscovery discovery, HttpMessageHandler handler = null)
        {
            WebApiRequest.InitializeHttpClient(handler);
            string host = discovery.GetHost();

            return(For <T>(host));
        }
コード例 #2
0
        /// <summary>
        /// 使用指定的HttpClient,HttpClient 需指定 BaseAddress
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="client"></param>
        /// <returns></returns>
        public static T For <T>(HttpClient client)
        {
            if (client == null || client.BaseAddress == null)
            {
                throw new InvalidOperationException("HttpClient or HttpClient.BaseAddress cannot be null");
            }
            WebApiRequest.InitializeHttpClient(client);
            string host = client.BaseAddress.Scheme + "://" + client.BaseAddress.Authority;

            return(For <T>(host));
        }
コード例 #3
0
        public virtual T Handle <T>(string path, string httpMethod, object data, string host)
        {
            if (string.IsNullOrEmpty(host))
            {
                host = GetHost();
            }
            string        url        = string.Concat(host.TrimEnd('/'), "/", path.TrimStart('/'));
            WebApiRequest apiRequest = new WebApiRequest();

            return(apiRequest.SendRequest <T>(url, httpMethod, data));
        }
コード例 #4
0
 /// <summary>
 /// 直接指定host
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="host"></param>
 /// <returns></returns>
 public static T For <T>(string host, HttpMessageHandler handler = null)
 {
     WebApiRequest.InitializeHttpClient(handler);
     return(DynamicProxy.CreateInstance <T>(host));
 }