ja08prat
ja08prat

Reputation: 154

How to receive a HTTP POST request in a C# program

I am writing a practice web application that verifies a sudoku board. A user will input a board as a single text string delimited by spaces on a super simple HTML webpage. I want to send that text string to a back-end program written in C# that will verify the board, and send verification messages to have them print on the web page below where the user entered the board. I already have the back end written and thoroughly tested, I am just super confused on how to link the front and back ends for data input and output. I want to send the user entered board using a POST request, but I am unsure how to receive a POST request in C# and I am unsure how to send messages from the back end to be displayed as output. I'd like my C# program's output to be printed to the webpage just as if I was printing to a terminal window.

Is there a different way other than POST/GET requests to communicate with web page?

I am very new to web application development and everything I am finding online is very overwhelming. I am not asking anyone to write this for me, all I am asking to be pointed in the correct direction.

Upvotes: 0

Views: 397

Answers (1)

KevinSantana11
KevinSantana11

Reputation: 31

Depends honestly on what your using.

If your using MVC 5 framework you will have to use an HTTP Get and Post Method which will involve some razor code.

ex:

C# Code:

    [HttpPost]
    public ActionResult verifyBoard(SudokuModel model)
    {

        boolean validBoard = checkSudokuBoard(model);
    }

HTML:

 @using (Html.BeginForm("verifyBoard", "Sudoku", FormMethod.Post))
        {
            <button type="submit">
             Submit Board
            </button>
        }

this example here is assuming your passing stuff from your HTML to your C# backend. MVC ties this with the model and using the attribute in the html so that the data is passed through with a HTTP POST.

I think what you want is to create a JSON object that will be passed through in a POST request. More on that could be found here : Apache with c# classes

If i were you I would look at the above post. If that's not what you wanted look into MVC 5 but if its a single page application I would using something else like ASP.NET webForms which makes building a web app very simple and straight forward.

Upvotes: 2

Related Questions