private async Task <HttpResponseMessage> PostRestMessage(Uri baseAddress, string restRelativeEndpoint, object jsonMessage, Dictionary <string, string> additionalHeaders = null, WebProxyInfo proxyInfo = null)
        {
            HttpResponseMessage response;

            using (var handler = new HttpClientHandler())
            {
                if (proxyInfo?.DoNotUseProxy ?? false)
                {
                    handler.UseProxy = false;
                }
                else if ((proxyInfo?.Proxy ?? null) != null)
                {
                    handler.Proxy = proxyInfo.Proxy;
                }

                using (var client = new HttpClient(handler))
                {
                    client.BaseAddress = baseAddress;
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    if (additionalHeaders != null)
                    {
                        foreach (var additionalHeader in additionalHeaders)
                        {
                            client.DefaultRequestHeaders.Add(additionalHeader.Key, additionalHeader.Value);
                        }
                    }
                    response = await client.PostAsJsonAsync(restRelativeEndpoint, jsonMessage);

                    response.EnsureSuccessStatusCode();
                }
            }
            return(response);
        }
        private async Task <HttpResponseMessage> PostForm(Uri baseAddress, string postEndpointUrl, Dictionary <string, string> formValues, Dictionary <string, string> additionalHeaders = null, WebProxyInfo proxyInfo = null)
        {
            HttpResponseMessage response;

            using (var handler = new HttpClientHandler())
            {
                if (proxyInfo?.DoNotUseProxy ?? false)
                {
                    handler.UseProxy = false;
                }
                else if ((proxyInfo?.Proxy ?? null) != null)
                {
                    handler.Proxy = proxyInfo.Proxy;
                }

                using (var client = new HttpClient(handler))
                {
                    client.BaseAddress = baseAddress;
                    if (additionalHeaders != null)
                    {
                        foreach (var additionalHeader in additionalHeaders)
                        {
                            client.DefaultRequestHeaders.Add(additionalHeader.Key, additionalHeader.Value);
                        }
                    }

                    response = await client.PostAsync(postEndpointUrl, new FormUrlEncodedContent(formValues));

                    response.EnsureSuccessStatusCode();
                }
            }
            return(response);
        }