/// <summary>
        /// Reads the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        public static HttpResponse Read(Stream stream)
        {
            HttpResponse response = new HttpResponse();
            StreamReader reader = new StreamReader(stream);


            // Status line
            string statusLine = reader.ReadLine();

            // Remove HTTP 
            int i = statusLine.IndexOf(' ');
            statusLine = statusLine.Substring(i + 1);

            // Get status code
            i = statusLine.IndexOf(' ');
            string statusCode = statusLine.Substring(0, i);
            response.StatusCode = int.Parse(statusCode);

            // Reason
            response.Reason = statusLine.Substring(i + 1);

            // Header
            string line = null;
            while (line != string.Empty)
            {
                line = reader.ReadLine();
            }

            // Content
            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                response.Content += line;
            }

            reader.Close();

            return response;
        }
Пример #2
0
        /// <summary>
        /// Reads the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        public static HttpResponse Read(Stream stream)
        {
            FrameworkLogs.Network.Info("Reading a HTTP response");

            HttpResponse response = new HttpResponse();
            StreamReader reader = new StreamReader(stream);


            // Status line
            var statusLine = reader.ReadLine();
            var elements = statusLine.Split(' ');

            response.StatusCode = int.Parse(elements[1]);
            response.Reason = elements[2];

            // Header
            string line = null;
            while (line != string.Empty)
            {
                line = reader.ReadLine();
            }

            // Content
            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                response.Content += line;
            }

            reader.Close();

            FrameworkLogs.Network.Info("Response read");
            FrameworkLogs.Network.Debug(response.StatusCode, response.Reason, response.Content);

            return response;
        }