-1

I'm trying to develop a program that handles POST and GET requests.

I've spent countless hours searching around the web for a tutorial that doesn't depend on ASP.NET I do not want to use ASP.NET just standard C#.

How can I achieve this? The furthest I've gotten to is this:

if (HttpMethod.ContentType == "POST") {
  // Code here
}

I've made a function HttpListen server on http://localhost:8080/ which sends a response.

What I'm looking for is you do http://localhost:8080/?method=val1&results=val2.

Thanks, Brown.

brownzilla
  • 289
  • 2
  • 3
  • 12
  • What you are looking for, is creating a http library in c#. Have you searched for something similar? – isnvi23h4 Nov 12 '15 at 00:50
  • I've searched everyone thing related to Http. I cannot seem to find anything. – brownzilla Nov 12 '15 at 00:58
  • Well, you'd have to start an application which listens on port 80, then study `http` protocols, and go from there. The code snippet you've put there doesn't really tell us anything about your current state... it doesn't relate to handling requests at all, it's part of the code you'd write once you've got the server implemented.. – Rob Nov 12 '15 at 01:00
  • I've done. I've made a functional Http Listen server. – brownzilla Nov 12 '15 at 01:00
  • have you check this : http://stackoverflow.com/questions/11394229/net-post-form-in-code-behind ?, if it's somehow related to your concern? – Francis Saul Nov 12 '15 at 01:02
  • @FrancisSaul As I said, I don't want anything to do with ASP.NET. – brownzilla Nov 12 '15 at 01:04
  • @brownzilla If you've made a functional Http server, I'm not sure what you're stuck on..? – Rob Nov 12 '15 at 01:15
  • I'm stuck on actually handling a post method like `http://localhost:8080/?method=val1&results=val2` – brownzilla Nov 12 '15 at 01:17
  • @brownzilla That's a get method, not a post method. In any case, you should read up on the http spec, it'll tell you exactly what to do and how to parse the query string. – Rob Nov 12 '15 at 01:18
  • Could you possibly provide a link for a recommended site. – brownzilla Nov 12 '15 at 01:20

1 Answers1

1

You're looking for an HTTP server library that is not ASP.NET?

Awkwardly bypassing the question "What's wrong with ASP.NET?"....

Nancy is an awesome lightweight open source library. You can find some samples on github, although the samples are a bit on the heavy side. If you're looking for an extremely basic setup you can get away with a couple dozen lines of code. A good example is the console-based self-hosted sample.

// add such a module class to your assembly, Nancy should find it automagically
public class ResourceModule : NancyModule
{
    public ResourceModule() : base("/products")
    {
        // would capture routes to /products/list sent as a GET request
        Get["/list"] = parameters => {
            return "The list of products";
        };
    }
}

// then start the host
using (var host = new NancyHost(new Uri("http://localhost:1234")))
{
   host.Start();
   // do whatever other work needed here because once the host is disposed of the server is gone 
   Console.ReadLine();
}
Sten Petrov
  • 10,943
  • 1
  • 41
  • 61