HttpServer.HttpResponse.Send C# (CSharp) Method

Send() public method

Send headers and body to the browser.
If content have already been sent.
public Send ( ) : void
return void
        public void Send()
        {
            if (!_headersSent)
                SendHeaders();
            if (_sent)
                throw new InvalidOperationException("Everyting have already been sent.");
            if (Body.Length == 0)
            {
                if (Connection == ConnectionType.Close)
                    _context.Disconnect(SocketError.Success);
                return;
            }

            Body.Flush();
            Body.Seek(0, SeekOrigin.Begin);
            byte[] buffer = new byte[4196];
            int bytesRead = Body.Read(buffer, 0, 4196);
            while (bytesRead > 0)
            {
                _context.Send(buffer, 0, bytesRead);
                bytesRead = Body.Read(buffer, 0, 4196);
            }

            if (Connection == ConnectionType.Close)
                _context.Disconnect(SocketError.Success);

            _sent = true;
        }

Usage Example

        public void Resonse(HttpResponse response, int type, string message)
        {
            //设置返回信息
            string content = JsonConvert.SerializeObject(new { type = type, message = message });

            //构造响应报文
            response.SetContent(content);
            response.Content_Encoding  = "utf-8";
            response.StatusCode        = "200";
            response.Content_Type      = "text/html;charset=UTF-8";
            response.Headers["Server"] = "ExampleServer";
            response.Headers["Access-Control-Allow-Origin"] = "*";
            response.Headers["Access-Control-Allow-Method"] = "POST,GET";

            //发送响应
            response.Send();
        }
All Usage Examples Of HttpServer.HttpResponse::Send