Esempio n. 1
0
        public async Task <IResponseMessage> SendAsync(
            HttpMethod method,
            string uriPath,
            Dictionary <string, object> uriQueryParams = null,
            object content   = null,
            TimeSpan?timeout = null)
        {
            var request = new HttpRequestMessage(method, GetFullUri(uriPath, uriQueryParams));

            request.Headers.Authorization = new AuthenticationHeaderValue(
                SenderConstants.AuthSidHeader,
                await AuthenticationProvider.GetSessionId());
            request.Headers.Add(SenderConstants.ApiKeyHeader, ApiKey);
            TryAddContent(content, request);
            if (timeout != null)
            {
                request.Headers.Add(SenderConstants.TimeoutHeader, timeout.Value.ToString("c"));
            }
            return(new ResponseMessage(await client.SendAsync(request)));
        }
        private async Task <Request> CreateRequest(
            HttpMethod method,
            string uriPath,
            Dictionary <string, object> uriQueryParams,
            object content,
            TimeSpan?timeout)
        {
            var request = new Request(
                method.ToString().ToUpperInvariant(),
                GetFullUri(uriPath, uriQueryParams),
                new Content(Convert.FromBase64String(JsonConvert.SerializeObject(content))))
                          .WithAuthorizationHeader(SenderConstants.AuthSidHeader, await AuthenticationProvider.GetSessionId())
                          .WithHeader(SenderConstants.ApiKeyHeader, ApiKey)
                          .WithContentTypeHeader(SenderConstants.MediaType);

            return(timeout != null?request.WithHeader(SenderConstants.TimeoutHeader, timeout.Value.ToString("c")) : request);
        }