Exemple #1
0
        private Result RequestAndRespond(HttpWebRequest request, string content)
        {
            HttpStatusCode statusCode = HttpStatusCode.NotFound;

            try
            {
                var contentBytes = Encoding.UTF8.GetBytes(content);
                request.ContentLength = contentBytes.Length;
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(contentBytes, 0, contentBytes.Length);
                }

                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    statusCode = this.StatusGetter.GetStatusCode(response);
                }
            }
            catch (WebException webException)
            {
                var response = webException.Response as HttpWebResponse;
                statusCode = this.StatusGetter.GetStatusCode(response);
                if (statusCode >= HttpStatusCode.InternalServerError)
                {
                    this.Logger.Err("HttpClient.RequestAndRespond exception {0} status code {1} request {2}", webException.ToString(), statusCode, request.RequestUri.ToString());
                }

                this.Logger.Debug("HttpClient.RequestAndRespond exception {0} status code {1}", webException.ToString(), statusCode);
            }

            return(HttpStatusCodeExtensions.ToResult(statusCode));
        }
Exemple #2
0
 public void WhenCallingToResultShouldReturnExpected(HttpStatusCode httpStatusCode, Result expected)
 {
     Assert.Equal(expected, HttpStatusCodeExtensions.ToResult(httpStatusCode));
 }