Handling POST requests

Nov 6, 2009 at 3:16 PM
Edited Nov 6, 2009 at 3:18 PM


Hi there! I've just started using your library and, after a few bumps, got it to work.

I want to create a simple server that will serve files from a public folder and generate dynamic html by haml. I've managed to accomplish both by using HttpServer.Sample as a starting point. However, I'm having problems handling requests with any parameters. Could anyone please show me an example of handling GET and POST parameters? This is what I have so far (I'll keep it short):


// The Correct() method is the only addition.
// The rest is the same as in
// HttpServer.Sample.Controllers.UserController.cs.

public class UserController : RequestController
    // ... 

    public string Correct()
        if (Request.Method == "POST")
            if (Request.Param.Contains("text"))
                return Render("response", Request.Param["text"]);
                return Render("response", "doesn't contain text param");
            return Render("response", "no post request");

Request.Param.Contains("text") always seems to return false. I am positive I'm using the correct <form> syntax in my html files. What am I doing wrong?

I'd appreciate any help you can give me!





Nov 6, 2009 at 3:25 PM

show me your form.

Nov 6, 2009 at 4:13 PM

I'll be very embarassed if it turns out there's been an error in it all along. ^^


<form action="/ispravi/" method="post"> 
<textarea name="text"></textarea> 
<br/> <input type="submit" value="ispravi"/> </form>



<form action="/user/correct/" method="post">
	<textarea name="text"></textarea> 
	<input type="submit" value="correct"/>




Nov 7, 2009 at 3:07 PM

If this is a problem that cannot be easily fixed, could anyone please show me a small (or not) -working- source example of an application that recieves data through POST requests?



Nov 7, 2009 at 4:20 PM

Also, if it helps any, here is the server's entry point. It's the only other server-specific .cs file in the project. So, the error should be either in these two files or in HttpServer itself. (Or in the above-posted HTML form.)


... snip ...

using HttpServer;
using HttpServer.HttpModules;
using HttpServer.Sessions;
using HttpServer.Helpers;
using HttpServer.Rendering;
using HttpServer.Controllers;
using HttpServer.Rendering.Haml;
using HttpServer.Exceptions;
using HttpServer.Rules;

... snip ...

    public class Web
        public void start(string[] args)
            TemplateManager mgr = new TemplateManager(new FileTemplateLoader("..\\views\\"));
            mgr.Add("haml", new HamlGenerator());

            HttpServer.HttpServer server  = new HttpServer.HttpServer();

            // file module will be handling files
            FileModule fh = new FileModule("/", "..\\public\\");

            // a controller mode implements a MVC pattern
            ControllerModule mod = new ControllerModule();
            mod.Add(new UserController(mgr));

            server.Start(IPAddress.Any, 9001);



Nov 8, 2009 at 8:56 PM

It seems I have been using an outdated build all along.

Many apologies. The code works now.

I hate it when the problem turns out to be this simple...

Nov 9, 2009 at 6:56 AM