public void sendRequest(
            string method,
            Uri url,
            int requestId,
            string[][] headers,
            JObject data,
            string responseType,
            bool useIncrementalUpdates,
            int timeout)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (responseType == null)
            {
                throw new ArgumentNullException(nameof(responseType));
            }
            if (responseType != "text" && responseType != "base64")
            {
                throw new ArgumentOutOfRangeException(nameof(responseType));
            }

            var request = new HttpRequestMessage(new HttpMethod(method), url);

            var headerData = default(HttpContentHeaderData);

            if (headers != null)
            {
                headerData = HttpContentHelpers.ExtractHeaders(headers);
                ApplyHeaders(request, headers);
            }

            if (data != null)
            {
                var body     = data.Value <string>("string");
                var uri      = default(string);
                var formData = default(JArray);
                if (body != null)
                {
                    if (headerData.ContentType == null)
                    {
                        OnRequestError(requestId, "Payload is set but no 'content-type' header specified.", false);
                        return;
                    }

                    request.Content = HttpContentHelpers.CreateFromBody(headerData, body);
                }
                else if ((uri = data.Value <string>("uri")) != null)
                {
                    if (headerData.ContentType == null)
                    {
                        OnRequestError(requestId, "Payload is set but no 'content-type' header specified.", false);
                        return;
                    }

                    _tasks.AddAndInvokeAsync(requestId, token => ProcessRequestFromUriAsync(
                                                 requestId,
                                                 new Uri(uri),
                                                 useIncrementalUpdates,
                                                 timeout,
                                                 request,
                                                 responseType,
                                                 token));

                    return;
                }
                else if ((formData = (JArray)data.GetValue("formData", StringComparison.Ordinal)) != null)
                {
                    if (headerData.ContentType == null)
                    {
                        headerData.ContentType = "multipart/form-data";
                    }

                    var formDataContent = new HttpMultipartFormDataContent();
                    foreach (var content in formData)
                    {
                        var fieldName = content.Value <string>("fieldName");

                        var stringContent = content.Value <string>("string");
                        if (stringContent != null)
                        {
                            formDataContent.Add(new HttpStringContent(stringContent), fieldName);
                        }
                    }

                    request.Content = formDataContent;
                }
            }

            _tasks.AddAndInvokeAsync(requestId, async token =>
            {
                using (request)
                {
                    try
                    {
                        await ProcessRequestAsync(
                            requestId,
                            useIncrementalUpdates,
                            timeout,
                            request,
                            responseType,
                            token);
                    }
                    finally
                    {
                        var content = request.Content;
                        if (content != null)
                        {
                            content.Dispose();
                        }
                    }
                }
            });
        }
        public void sendRequest(
            string method,
            Uri url,
            int requestId,
            string[][] headers,
            JObject data,
            bool useIncrementalUpdates,
            int timeout)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            var request = new HttpRequestMessage(new HttpMethod(method), url);

            var headerData = default(HttpContentHeaderData);

            if (headers != null)
            {
                headerData = HttpContentHelpers.ExtractHeaders(headers);
                ApplyHeaders(request, headers);
            }

            if (data != null)
            {
                var body     = data.Value <string>("string");
                var uri      = default(string);
                var formData = default(JArray);
                if (body != null)
                {
                    if (headerData.ContentType == null)
                    {
                        OnRequestError(requestId, "Payload is set but no 'content-type' header specified.", false);
                        return;
                    }

                    request.Content = HttpContentHelpers.CreateFromBody(headerData, body);
                }
                else if ((uri = data.Value <string>("uri")) != null)
                {
                    if (headerData.ContentType == null)
                    {
                        OnRequestError(requestId, "Payload is set but no 'content-type' header specified.", false);
                        return;
                    }

                    _tasks.Add(requestId, token => ProcessRequestFromUriAsync(
                                   requestId,
                                   new Uri(uri),
                                   useIncrementalUpdates,
                                   timeout,
                                   request,
                                   token));

                    return;
                }
                else if ((formData = data.Value <JArray>("formData")) != null)
                {
                    if (headerData.ContentType == null)
                    {
                        headerData.ContentType = "multipart/form-data";
                    }

                    var formDataContent = new HttpMultipartFormDataContent();
                    foreach (var content in formData)
                    {
                        var fieldName = content.Value <string>("fieldName");

                        var stringContent = content.Value <string>("string");
                        if (stringContent != null)
                        {
                            formDataContent.Add(new HttpStringContent(stringContent), fieldName);
                        }
                    }

                    request.Content = formDataContent;
                }
            }

            _tasks.Add(requestId, token => ProcessRequestAsync(
                           requestId,
                           useIncrementalUpdates,
                           timeout,
                           request,
                           token));
        }