示例#1
0
        protected override async Task WriteStreamingHeader()
        {
            using (var timeout = new CancellationTokenSource(3000))
            {
                var b = Encoding.ASCII.GetBytes(
                    "HTTP/1.1 200 OK\r\n" +
                    "Content-Type: multipart/x-mixed-replace; boundary=" +
                    BOUNDARY +
                    "\r\n"
                    );
                await Ns.WriteAsync(b, 0, b.Length);

                await Ns.FlushAsync();
            }
        }
        protected async Task SendTextRensponse(string status, string mimeType, string content)
        {
            var contentBytes = Encoding.UTF8.GetBytes(content);
            var header       =
                "HTTP/1.1 " + status + "\r\n" +
                "Cache-Control: no-cache\r\n" +
                "Content-Length: " + contentBytes.Length.ToString(CultureInfo.InvariantCulture) + "\r\n" +
                "Content-Type: " + mimeType + "\r\n\r\n";

            var headerBytes = Encoding.ASCII.GetBytes(header);

            using (var timeout = new CancellationTokenSource(3000))
            {
                timeout.Token.Register(() => Ns.Close());
                await Ns.WriteAsync(headerBytes, 0, headerBytes.Length);

                await Ns.WriteAsync(contentBytes, 0, contentBytes.Length);

                await Ns.FlushAsync();
            }
        }