Giter Site home page Giter Site logo

Comments (4)

stratdev3 avatar stratdev3 commented on August 16, 2024 1

@shamooraee i made a lib which encapsulate NetCoreServer and and bring some features like serving both static files and rest api.

As reading you, it seems it can fit your needs

from netcoreserver.

shamooraee avatar shamooraee commented on August 16, 2024

I made this in OnRequestRecieved and it works...

            if (request.Method == "HEAD")
                SendResponseAsync(Response.MakeHeadResponse());
            else if (request.Method == "GET" && request.Url == "/")
            {
                string responseString = @"
                <html>
                    <body>
                        <form action='/' method='post'>
                            <label for='input1'>Input 1:</label>
                            <input type='text' id='input1' name='input1'><br><br>
                            <label for='input2'>Input 2:</label>
                            <input type='text' id='input2' name='input2'><br><br>
                            <input type='submit' value='Submit'>
                        </form>
                    </body>
                </html>";
            
                SendResponseAsync(Response.MakeGetResponse(responseString, "text/html; charset=UTF-8"));
            }
            else if ((request.Method == "POST") || (request.Method == "PUT"))
            {
                var body = request.Body;
                var parameters = body.Split('&');
                var input1 =  WebUtility.UrlDecode(parameters[0].Split('=')[1]);
                var input2 = WebUtility.UrlDecode(parameters[1].Split('=')[1]);
            
                Response.Clear();
                Response.SetBegin(302);
                Response.SetHeader("Location", "/success");
                Response.SetBody();
            
                SendResponseAsync(Response);
            }
            else if (request.Url == "/success")
            {
                string responseString = @"
                <html>
                    <body>
                        <h1>Form Submitted Successfully!</h1>
                        <p>Your data has been saved.</p>
                    </body>
                </html>";
            
                SendResponseAsync(Response.MakeGetResponse(responseString, "text/html; charset=UTF-8"));
            }
            else if (request.Method == "OPTIONS")
                SendResponseAsync(Response.MakeOptionsResponse());
            else if (request.Method == "TRACE")
                SendResponseAsync(Response.MakeTraceResponse(request));
            else
                SendResponseAsync(Response.MakeErrorResponse("Unsupported HTTP method: " + request.Method));

from netcoreserver.

shamooraee avatar shamooraee commented on August 16, 2024

Got it working completely, thanks anyway! If you see any good things to consider in it let me know.

from netcoreserver.

shamooraee avatar shamooraee commented on August 16, 2024

@stratdev3 awesome! Thank you both!
Btw.. exactly my thoughts and why I am here at all: https://github.com/stratdev3/SimpleW?tab=readme-ov-file#the-existings-projects

from netcoreserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.