Here's an example of how to create a simple HTTP server with a POST route in C# using the built-in HttpListener
class:
main.cs1403 chars46 lines
This code listens for requests on http://localhost:8080/
and checks if a received request is a POST
request with the path /example-route
. If it is, it reads the request body and logs it to the console, then responds with a 200 OK
status code. If the request is something else, it responds with a 404 Not Found
status code.
Note that this is a very basic example and not suitable for production use. In a real-world application, you would likely want to use a more robust framework, such as ASP.NET or NancyFX, to handle routing and request handling.
gistlibby LogSnag