private SdkResponse _http(string url, string method, string contentType, Dictionary <string, string> headers,
                                  string content)
        {
            var request = GetHttpRequest(url, method, contentType, headers, content);

            _credential.SignAuthRequest(request);
            var client  = new SdkHttpClient(_httpConfig);
            var message = client.InitHttpRequest(request);
            var result  = new SdkResponse();

            try
            {
                var task      = client.DoHttpRequest(message);
                var requestId = task.Result.Headers.GetValues(XRequestId).FirstOrDefault();
                result.HttpStatusCode = (int)task.Result.StatusCode;
                result.HttpHeaders    = task.Result.Headers.ToString();
                result.HttpBody       = task.Result.Content.ReadAsStringAsync().Result;
                if (result.HttpStatusCode < 400)
                {
                    return(result);
                }

                SdkError sdkError;
                try
                {
                    sdkError = GetSdkErrorFromResponse(requestId, result);
                }
                catch (Exception exception)
                {
                    throw new ServerResponseException(result.HttpStatusCode,
                                                      new SdkError {
                        ErrorMsg = exception.Message
                    });
                }

                if (result.HttpStatusCode >= 400 && result.HttpStatusCode < 500)
                {
                    throw new ClientRequestException(result.HttpStatusCode, sdkError);
                }

                throw new ServerResponseException(result.HttpStatusCode, sdkError);
            }
            catch (AggregateException aggregateException)
            {
                throw new ConnectionException(aggregateException.Message);
            }
        }
Пример #2
0
 private void InitSdkHttpClient(HttpHandler httpHandler, bool enableLogging, LogLevel logLevel)
 {
     this._sdkHttpClient =
         new SdkHttpClient(this.GetType().FullName, _httpConfig, httpHandler, enableLogging, logLevel);
 }