Ejemplo n.º 1
0
        public static async Task <HttpResponseResult> GetApiDataAsync(RequestMethod method, string uri, string data, string contentType)
        {
            HttpWebRequest request          = CreateHttpRequest(method, uri, data, contentType);
            var            httpResponseData = string.Empty;
            HttpStatusCode statusCode       = HttpStatusCode.Continue; //Status code 100

            try
            {
                using (var response = await request.GetResponseAsync())
                {
                    var httpResponse = response as HttpWebResponse;
                    statusCode = httpResponse.StatusCode;
                    using (Stream stream = response.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            httpResponseData = reader.ReadToEnd();
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                var httpResponse = (HttpWebResponse)ex.Response;
                statusCode = httpResponse.StatusCode;
            }
            var responseResult = new HttpResponseResult(statusCode, httpResponseData);

            return(responseResult);
        }
Ejemplo n.º 2
0
        public static async Task <HttpResponseResult> GetApiDataAsync(HttpWebRequest request)
        {
            var            httpResponseData = string.Empty;
            HttpStatusCode statusCode       = HttpStatusCode.Continue; //Status code 100
            WebResponse    response         = null;

            try
            {
                using (response = await request.GetResponseAsync())
                {
                    var httpResponse = response as HttpWebResponse;
                    statusCode = httpResponse.StatusCode;
                    using (Stream stream = response.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            httpResponseData = reader.ReadToEnd();
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                var httpResponse = (HttpWebResponse)ex.Response;
                statusCode = httpResponse.StatusCode;
            }
            var responseResult = new HttpResponseResult(statusCode, httpResponseData);

            return(responseResult);
        }
Ejemplo n.º 3
0
 private static IList <Dictionary <string, object> > ThrowIfResponseCantParseOrReturnResponseDictCollection(HttpResponseResult result)
 {
     try
     {
         return(result.GetApiData(JsonConvert.DeserializeObject <IList <Dictionary <string, object> > >));
     }
     catch (Exception ex)
     {
         var exception = new TestRailApiException($"Error occurs when parse response when try to get data Dictionary<string, object>", ex);
         throw exception;
     }
 }