private async Task<TrackingResult> RequestUrlAsync(string url, IDictionary<string, string> parameters, string userAgent = null)
        {
            // Create GET string
            var data = new StringBuilder();
            foreach (var parameter in parameters)
            {
                data.Append(string.Format("{0}={1}&", parameter.Key, Uri.EscapeDataString(parameter.Value)));
            }

            // Build TrackingResult
            var returnValue = new TrackingResult
            {
                Url = url,
                Parameters = parameters
            };

            // Determine referer URL
            var referer = string.Format("http://{0}/", TrackingDomain);
            if (parameters.ContainsKey("ReferralUrl"))
            {
                referer = parameters["ReferralUrl"];
            }

            // Create request
            HttpWebRequest request;
            try
            {
                request = (HttpWebRequest)WebRequest.Create(string.Format("{0}?{1}", url, data));                
                request.SetHeader("Referer", referer);
                request.SetHeader("User-Agent", userAgent ?? UserAgent);
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)                
                    throw;                
                
                returnValue.Success = false;
                returnValue.Exception = ex;
                return returnValue;
            }

            // Perform request
            WebResponse response = null;
            try
            {
                response = await Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
                returnValue.Success = true;
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)                
                    throw;                
                else
                {
                    returnValue.Success = false;
                    returnValue.Exception = ex;
                }
            }
            finally
            {
                if (response != null)                
                    response.Dispose();                
            }

            return returnValue;
        }
        private async Task <TrackingResult> RequestUrlAsync(string url, IDictionary <string, string> parameters, string userAgent)
        {
            // Create GET string
            var data = new StringBuilder();

            foreach (var parameter in parameters.OrderBy(p => p.Key, new BeaconComparer()))
            {
                data.Append(string.Format("{0}={1}&", parameter.Key, Uri.EscapeDataString(parameter.Value)));
            }

            // Build TrackingResult
            var returnValue = new TrackingResult
            {
                Url        = url,
                Parameters = parameters
            };

            // Create request
            HttpRequestMessage request;

            try
            {
                request = UseHttpGet
                    ? CreateGetWebRequest(url, data.ToString())
                    : CreatePostWebRequest(url, data.ToString());

                if (!string.IsNullOrEmpty(userAgent))
                {
                    request.Headers.Add("User-Agent", userAgent);
                }
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)
                {
                    throw;
                }

                returnValue.Success   = false;
                returnValue.Exception = ex;

                return(returnValue);
            }

            // Perform request
            HttpResponseMessage response = null;

            try
            {
                response = await HttpClient.SendAsync(request);

                returnValue.Success = true;
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)
                {
                    throw;
                }
                else
                {
                    returnValue.Success   = false;
                    returnValue.Exception = ex;
                }
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
            }

            return(returnValue);
        }
        private async Task <TrackingResult> RequestUrlAsync(string url, IDictionary <string, string> parameters, string userAgent = null)
        {
            // Create GET string
            var data = new StringBuilder();

            foreach (var parameter in parameters)
            {
                data.Append(string.Format("{0}={1}&", parameter.Key, Uri.EscapeDataString(parameter.Value)));
            }

            // Build TrackingResult
            var returnValue = new TrackingResult
            {
                Url        = url,
                Parameters = parameters
            };

            // Determine referer URL
            var referer = string.Format("http://{0}/", TrackingDomain);

            if (parameters.ContainsKey("ReferralUrl"))
            {
                referer = parameters["ReferralUrl"];
            }

            // Create request
            HttpRequestMessage requestMessage;

            try
            {
                requestMessage = new HttpRequestMessage(HttpMethod.Get, string.Format("{0}?{1}", url, data));
                requestMessage.Headers.Add("Referer", referer);
                requestMessage.Headers.Add("User-Agent", userAgent ?? UserAgent);
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)
                {
                    throw;
                }

                returnValue.Success   = false;
                returnValue.Exception = ex;
                return(returnValue);
            }

            // Perform request
            HttpResponseMessage response = null;

            try
            {
                response = await _httpClient.SendAsync(requestMessage);

                returnValue.Success = true;
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)
                {
                    throw;
                }
                else
                {
                    returnValue.Success   = false;
                    returnValue.Exception = ex;
                }
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
            }

            return(returnValue);
        }
        private async Task <TrackingResult> RequestUrlAsync(string url, Dictionary <string, string> parameters, string userAgent = null)
        {
            // Create GET string
            StringBuilder data = new StringBuilder();

            foreach (var parameter in parameters)
            {
                data.Append(string.Format("{0}={1}&", parameter.Key, Uri.EscapeDataString(parameter.Value)));
            }

            // Build TrackingResult
            var returnValue = new TrackingResult
            {
                Url        = url,
                Parameters = parameters
            };

            // Determine referer URL
            var referer = string.Format("http://{0}/", TrackingDomain);

            if (parameters.ContainsKey(BeaconParameter.Browser.ReferralUrl))
            {
                referer = parameters[BeaconParameter.Browser.ReferralUrl];
            }

            // Create request
            HttpWebRequest request = null;

            try
            {
                request = (HttpWebRequest)WebRequest.Create(string.Format("{0}?{1}", url, data));
                request.CookieContainer = CookieContainer;
                request.SetHeader("Referer", referer);
                request.SetHeader("User-Agent", userAgent ?? UserAgent);
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)
                {
                    throw;
                }
                else
                {
                    returnValue.Success   = false;
                    returnValue.Exception = ex;
                }
            }

            // Perform request
            WebResponse response = null;

            try
            {
                response = await Task.Factory.FromAsync <WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);

                returnValue.Success = true;
            }
            catch (Exception ex)
            {
                if (ThrowOnErrors)
                {
                    throw;
                }
                else
                {
                    returnValue.Success   = false;
                    returnValue.Exception = ex;
                }
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(returnValue);
        }