Beispiel #1
0
        public static string getRawResponseBody(HttpWebResponse response)
        {
            HttpStatusCode statusCode  = response.StatusCode;
            Stream         sResponse   = response.GetResponseStream();
            StreamReader   srResponse  = new StreamReader(sResponse);
            string         rawResponse = srResponse.ReadToEnd();

            if (statusCode != HttpStatusCode.OK)
            {
                throw CommunicationException.createFromHTTPResponse(statusCode, rawResponse);
            }

            return(rawResponse);
        }
Beispiel #2
0
        public static HttpWebResponse send(HttpClient client, HttpWebRequest request)
        {
            try
            {
                return(client.send(request));
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse response    = (HttpWebResponse)ex.Response;
                    HttpStatusCode  statusCode  = response.StatusCode;
                    Stream          sResponse   = response.GetResponseStream();
                    StreamReader    srResponse  = new StreamReader(sResponse);
                    string          rawResponse = srResponse.ReadToEnd();

                    throw CommunicationException.createFromHTTPResponse(statusCode, rawResponse);
                }
                throw new CommunicationException("RequestException", ex, CommunicationException.GENERAL_HTTP_ERROR);
            }
        }