Esempio n. 1
0
        public async Task <T> SendStreamContent <T>(string url, string apiToken, HttpMethod method, IEnumerable <KeyValuePair <string, string> > parameters = null, StreamReader body = null)
        {
            var uri = new Uri(url);

            if (parameters != null)
            {
                uri.AddParameters(parameters.ToList());
            }
            using (var requestMessage = new HttpRequestMessage(method, uri))
            {
                requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                if (body != null)
                {
                    requestMessage.Content = new StreamContent(body.BaseStream);
                }
                requestMessage.Content.Headers.Add("Content-Type", "text/csv");

                return(await MakeRequest <T>(apiToken, requestMessage).ConfigureAwait(false));
            }
        }
Esempio n. 2
0
        public async Task <T> SendObjectContent <T>(string url, string apiToken, HttpMethod method, IEnumerable <KeyValuePair <string, string> > parameters = null, object body = null)
        {
            var uri = new Uri(url);

            if (parameters != null)
            {
                uri.AddParameters(parameters.ToList());
            }
            using (var requestMessage = new HttpRequestMessage(method, uri))
            {
                requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var settings = new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                };
                if (body != null)
                {
                    requestMessage.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(body, settings)));
                }
                requestMessage.Content.Headers.Add("Content-Type", "application/json");

                return(await MakeRequest <T>(apiToken, requestMessage).ConfigureAwait(false));
            }
        }