示例#1
0
        /// <summary>
        /// A method is used to read the HTTP response body and decode to string.
        /// </summary>
        /// <param name="wopiHttpResponse">A parameter represents the HTTP response.</param>
        /// <returns>A return value represents the string which is decode from the HTTP response body. The decode format is UTF-8 by default.</returns>
        public static string ReadHTTPResponseBodyToString(WOPIHttpResponse wopiHttpResponse)
        {
            if (null == wopiHttpResponse)
            {
                throw new ArgumentNullException("wopiHttpResponse");
            }

            string bodyString = string.Empty;
            long   bodyLength = wopiHttpResponse.ContentLength;

            if (bodyLength != 0)
            {
                Stream bodStream = null;
                try
                {
                    bodStream = wopiHttpResponse.GetResponseStream();
                    using (StreamReader strReader = new StreamReader(bodStream))
                    {
                        bodyString = strReader.ReadToEnd();
                    }
                }
                finally
                {
                    if (bodStream != null)
                    {
                        bodStream.Dispose();
                    }
                }
            }

            return(bodyString);
        }
示例#2
0
        /// <summary>
        /// A method is used to read the HTTP response body to the bytes array.
        /// </summary>
        /// <param name="wopiHttpResponse">A parameter represents the HTTP response.</param>
        /// <returns>A return value represents the raw body content. If the body length is larger than (int.MaxValue) bytes, the body contents will be chunked by 1024 bytes. The max length of this method is (1024 * int.MaxValue) bytes.</returns>
        public static List <byte[]> ReadRawHTTPResponseToBytes(WOPIHttpResponse wopiHttpResponse)
        {
            if (null == wopiHttpResponse)
            {
                throw new ArgumentNullException("wopiHttpResponse");
            }

            using (Stream bodyStream = wopiHttpResponse.GetResponseStream())
            {
                long contentLengthValue = wopiHttpResponse.ContentLength;
                return(ReadBytesFromHttpBodyStream(bodyStream, contentLengthValue));
            }
        }