Пример #1
0
        public override void OnOperation(HttpListenerContext context, Authentication authentication)
        {
            Arguments arguments = GetArguments(context);

            ContentType = "text/plain";
            StatusCode  = HttpStatusCode.OK;
            string text;

            if (arguments != null)
            {
                text = OnOperation(arguments, authentication);

                context.Response.ContentType = ContentType;
                context.Response.StatusCode  = (int)StatusCode;
            }
            else
            {
                text       = "The provided request was invalid";
                StatusCode = HttpStatusCode.BadRequest;
            }

            HttpStream stream = new HttpStream(context.Response);

            stream.Send(text);
            stream.Close();
        }
Пример #2
0
        public static void Rederect(HttpListenerContext context, string url)
        {
            context.Response.Redirect(url);
            HttpStream httpStream = new HttpStream(context.Response);

            httpStream.Send("re-routed");
            httpStream.Close();
        }
Пример #3
0
        public static void SendErrorPage(HttpListenerResponse response, string message, bool isError, HttpStatusCode status)
        {
            int    statusCode = -1;
            string html       = Encoding.UTF8.GetString(WebsiteRequestProcessor.OnRequest("/errorPage.html", out string contentType, ref statusCode));

            response.StatusCode  = (int)status;
            response.ContentType = "text/html";
            html = Utils.FormatString(html, message, isError ? "" : "display: none;", isError ? "display: none;" : "");

            HttpStream stream = new HttpStream(response);

            stream.Send(html);
            stream.Close();
        }
Пример #4
0
        public override void OnOperation(HttpListenerContext context, Authentication authentication)
        {
            Arguments arguments = GetArguments(context);

            ContentType = "application/json";
            StatusCode  = HttpStatusCode.OK;

            JsonOperationResponseBase operationResponseBase;

            if (arguments != null)
            {
                operationResponseBase = OnOperation(arguments, authentication);

                context.Response.ContentType = ContentType;
                context.Response.StatusCode  = (int)StatusCode;
            }
            else
            {
                StatusCode            = HttpStatusCode.BadRequest;
                operationResponseBase = new JsonOperationResponseBase()
                {
                    Error = "The provided request was invalid"
                };
            }

            if (operationResponseBase != null)
            {
                HttpStream stream = new HttpStream(context.Response);
                stream.Send(operationResponseBase.ToJson());
                stream.Close();
            }
            else
            {
                HttpStream stream = new HttpStream(context.Response);
                stream.Send("null");
                stream.Close();
            }
        }
Пример #5
0
        static async void listenHttp(HttpListener httpListener)
        {
            while (true)
            {
                var context = await httpListener.GetContextAsync();

                //Console.WriteLine("Client connected");
                Task.Factory.StartNew(() =>
                {
                    UriBuilder builder = new UriBuilder(context.Request.Url);

                    builder.Scheme = "https";
                    builder.Port   = 443;

                    string url = builder.Uri.ToString();

                    context.Response.Redirect(url);
                    HttpStream httpStream = new HttpStream(context.Response);
                    httpStream.Send("Re-rounted to https");
                    httpStream.Close();
                });
            }
        }