GetTextOfWebResponse() private static method

private static GetTextOfWebResponse ( HttpWebResponse webResponse ) : string
webResponse System.Net.HttpWebResponse
return string
        private Response CreateResponse(WebRequest request)
        {
            Response        response        = new Response();
            HttpWebResponse httpWebResponse = null;

            try
            {
                httpWebResponse = (request.GetResponse() as HttpWebResponse);
            }
            catch (WebException ex)
            {
                httpWebResponse = (ex.Response as HttpWebResponse);
                if (ex.Status == WebExceptionStatus.Timeout)
                {
                    string format = "The HTTP request to the remote WebDriver server for URL {0} timed out after {1} seconds.";
                    throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, format, new object[]
                    {
                        request.RequestUri.AbsoluteUri,
                        this.serverResponseTimeout.TotalSeconds
                    }), ex);
                }
                if (ex.Response == null)
                {
                    string format2 = "A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL {0}. The status of the exception was {1}, and the message was: {2}";
                    throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, format2, new object[]
                    {
                        request.RequestUri.AbsoluteUri,
                        ex.Status,
                        ex.Message
                    }), ex);
                }
            }
            if (httpWebResponse == null)
            {
                throw new WebDriverException("No response from server for url " + request.RequestUri.AbsoluteUri);
            }
            string textOfWebResponse = HttpCommandExecutor.GetTextOfWebResponse(httpWebResponse);

            if (httpWebResponse.ContentType != null && httpWebResponse.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
            {
                response = Response.FromJson(textOfWebResponse);
            }
            else
            {
                response.Value = textOfWebResponse;
            }
            if (this.commandInfoRepository.SpecificationLevel < 1 && (httpWebResponse.StatusCode < HttpStatusCode.OK || httpWebResponse.StatusCode >= HttpStatusCode.BadRequest))
            {
                if (httpWebResponse.StatusCode >= HttpStatusCode.BadRequest && httpWebResponse.StatusCode < HttpStatusCode.InternalServerError)
                {
                    response.Status = WebDriverResult.UnhandledError;
                }
                else if (httpWebResponse.StatusCode >= HttpStatusCode.InternalServerError)
                {
                    if (httpWebResponse.StatusCode == HttpStatusCode.NotImplemented)
                    {
                        response.Status = WebDriverResult.UnknownCommand;
                    }
                    else if (response.Status == WebDriverResult.Success)
                    {
                        response.Status = WebDriverResult.UnhandledError;
                    }
                }
                else
                {
                    response.Status = WebDriverResult.UnhandledError;
                }
            }
            if (response.Value is string)
            {
                response.Value = ((string)response.Value).Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
            }
            httpWebResponse.Close();
            return(response);
        }