Ejemplo n.º 1
0
        public static SdkRequest InitSdkRequest(string path, String contentType, object data = null)
        {
            if (path != null && string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("Url cannot be null.");
            }

            var request = new SdkRequest {
                Path = path
            };

            if (data == null)
            {
                return(request);
            }

            var prams = GetQueryParameters(data);

            if (prams != "")
            {
                request.QueryParams = prams;
            }

            var headers = GetRequestHeader(data);

            if (headers != null)
            {
                request.Header = headers;
            }

            var bodyData = GetRequestBody(data);

            if (bodyData != null)
            {
                request.Body = bodyData;
            }

            if (!string.IsNullOrEmpty(contentType))
            {
                request.ContentType = contentType;
                request.Header.Add("Content-Type", request.ContentType);
            }

            if (data.GetType().IsSubclassOf(typeof(SdkStreamRequest)))
            {
                request.FileStream = ((SdkStreamRequest)data).FileStream;
            }

            return(request);
        }
Ejemplo n.º 2
0
        private HttpResponseMessage _sync_http(string url, string method, SdkRequest sdkRequest)
        {
            var request = GetHttpRequest(url, method, sdkRequest);

            request = _credential.SignAuthRequest(request).Result;

            var message = this._sdkHttpClient.InitHttpRequest(request);

            try
            {
                var response = this._sdkHttpClient.DoHttpRequest(message).Result;
                return(GetResult(response));
            }
            catch (AggregateException aggregateException)
            {
                throw new ConnectionException(aggregateException.Message);
            }
        }
Ejemplo n.º 3
0
        private HttpResponseMessage _sync_http(string url, string method, SdkRequest sdkRequest)
        {
            var request = GetHttpRequest(url, method, sdkRequest);

            if (IsNullOrEmpty(request.Headers.Get("Authorization")))
            {
                request = _credential.SignAuthRequest(request).Result;
            }

            var message = this._sdkHttpClient.InitHttpRequest(request, _httpConfig.IgnoreBodyForGetRequest);

            try
            {
                var response = this._sdkHttpClient.DoHttpRequest(message).Result;
                return(GetResult(response));
            }
            catch (AggregateException aggregateException)
            {
                throw new ConnectionException(aggregateException.Message);
            }
        }
Ejemplo n.º 4
0
        protected async Task <HttpResponseMessage> DoHttpRequestAsync(string methodType, SdkRequest request)
        {
            var url = _endpoint
                      + HttpUtils.AddUrlPath(request.Path, _credential.GetPathParamDictionary())
                      + (IsNullOrEmpty(request.QueryParams) ? "" : "?" + request.QueryParams);

            return(await _async_http(url, methodType.ToUpper(), request));
        }