Exemplo n.º 1
0
        public HttpResponseMessage Execute(ApiParameter parameter, HttpMethod method)
        {
            var httoUtils = new HttpUtils();
            var handler1  = new HttpClientHandler
            {
                ClientCertificateOptions = ClientCertificateOption.Manual,
                ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true
            };

            var client = new HttpClient(handler1);

            var buildUrl = new UriBuilder(BaseAddress)
            {
                Path = UriPath, Query = httoUtils.ToQueryString(parameter)
            };

            var request = new HttpRequestMessage()
            {
                RequestUri = buildUrl.Uri,
                Method     = method,
                Headers    =
                {
                    { HttpRequestHeader.Accept.ToString(), "application/json" },
                    { "User-Agent",                        "api"              }
                }
            };

            return(client.SendAsync(request).Result);
        }
Exemplo n.º 2
0
        public string ToQueryString(ApiParameter parameter)
        {
            var list = parameter.GetParameters().Select(item => item.Key + "=" + item.Value).ToList();

            return(string.Join("&", list));
        }