コード例 #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
ファイル: Utils.cs プロジェクト: X606/ModBotBackend
        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
ファイル: Utils.cs プロジェクト: X606/ModBotBackend
        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
ファイル: Program.cs プロジェクト: X606/ModBotBackend
        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();
                });
            }
        }