Parameters Empty

Oct 2, 2010 at 8:53 AM

I know I must be missing something simple. 
Can someone please point out why I never see any values in the Form, Parameters, or QueryString?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HttpServer;
using System.Threading;
using HttpServer.Headers;
using HttpServer.Helpers;

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            HttpListener listener = HttpListener.Create(System.Net.IPAddress.Loopback, 8080);
            listener.RequestReceived += OnRequest;

            HttpServer.Server server = new Server();
            server.Add(listener);

            listener.Start(5);
            Thread.Sleep(9000000);
        }

        private static void OnRequest(object sender, RequestEventArgs e)
        {
            e.Response.Connection.Type = ConnectionType.Close;
            if (e.Request.Parameters.Count > 0)  // <----This never evaluates to true.
            {
                //Do Stuff
            } byte[] buffer = GetResponse(e); e.Response.Body.Write(buffer, 0, buffer.Length); } private static byte[] GetResponse(RequestEventArgs e) { byte[] buffer; buffer = Encoding.UTF8.GetBytes("<html><body><form name=\"form1\" action=\"login\" method=\"post\">Password: <input type=\"text\" /><input type=\"submit\" value=\"Submit\" /></form></body></html>"); return buffer; } } Thanks!!
Eric
Oct 12, 2010 at 1:09 AM

I've also found the same thing and managed to find a workaround.  If you take a look at Request.cs, you'll see 

// Parse query string.
int pos = path.IndexOf("?");
QueryString = pos != -1 ? UrlParser.Parse(path.Substring(pos + 1)) : new ParameterCollection();
Parameters = QueryString;

And that the only reference to Request.Form (_form) is via the DecodeBody() method in the Server class, which gives me the suspicion that form fields are only parsed when using a Server to manage your HttpListeners.

Anyhow, turns out you can grab the Body stream from the request, and use HttpServer.Tools.Parser to get a ParameterCollection for your form;

StreamReader reader = new StreamReader(e.Request.Body);
ParameterCollection parameters = UrlParser.Parse(reader.ReadToEnd());

 

Coordinator
Oct 12, 2010 at 5:33 AM
Sorry for the lack of response. My workload is huge. I'll fix this as soon as I got some spare time.

On Tue, Oct 12, 2010 at 3:09 AM, staff0rd <notifications@codeplex.com> wrote:

From: staff0rd

I've also found the same thing and managed to find a workaround.  If you take a look at Request.cs, you'll see 

// Parse query string.
int pos = path.IndexOf("?");
QueryString = pos != -1 ? UrlParser.Parse(path.Substring(pos + 1)) : new ParameterCollection();
Parameters = QueryString;

And that the only reference to Request.Form (_form) is via the DecodeBody() method in the Server class, which gives me the suspicion that form fields are only parsed when using a Server to manage your HttpListeners.

Anyhow, turns out you can grab the Body stream from the request, and use HttpServer.Tools.Parser to get a ParameterCollection for your form;

StreamReader reader = new StreamReader(e.Request.Body);
ParameterCollection parameters = UrlParser.Parse(reader.ReadToEnd());

 

Read the full discussion online.

To add a post to this discussion, reply to this email (webserver@discussions.codeplex.com)

To start a new discussion for this project, email webserver@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com