Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4120432
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:13:16+00:00 2026-05-20T23:13:16+00:00

I have a HttpListenerRequest which was initiated from a html <form> that was posted.

  • 0

I have a HttpListenerRequest which was initiated from a html <form> that was posted. I need to know how to get the posted form values + the uploaded files. Does anyone know of an example to save me the time doing it for myself? I’ve had a google around but not found anything of use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:13:17+00:00Added an answer on May 20, 2026 at 11:13 pm

    Odd that an accepted answer with full source code + a link to download
    a working demo would result in a negative score and votes to be
    deleted. If I were the kind of person who cared about my score I’d
    have deleted this answer, and then nobody would have benefited.
    Psychology, eh 🙂

    I found a few examples of web servers for MonoTouch but none of them parsed the data sent in a POST request. I looked around the web and was unable to find any examples of how to achieve this. So now that I’ve written it myself I’ve decided to share my own implementation. This includes not only the code for processing the form post data but also for registering request handlers etc.

    Here is an example of how you would use the web server

     public BookUploadViewController() 
       : base("BookUploadViewController", null)
     {
       RequestHandler = new DefaultRequestHandler();
       var defaultActionHandlerFactory = new DefaultActionHandlerFactory();
       RegisterActionHandlers(defaultActionHandlerFactory);
       RequestHandler.AddActionHandlerFactory(defaultActionHandlerFactory);
    
       WebServer = new EmbeddedWebServer(RequestHandler);
     }
    
     void RegisterActionHandlers(DefaultActionHandlerFactory factory)
     {
       factory.RegisterHandler(
         request => request.RawUrl == "/",
         request => new IndexActionHandler(request)
         );
       factory.RegisterHandler(
         request => 
           string.Compare(request.RawUrl, "/Upload", true) == 0 && 
           string.Compare(request.HttpMethod, "POST", true) == 0,
         request => new UploadActionHandler(request)
         );
     }
    
     public override void ViewDidAppear(bool animated)
     {
       base.ViewDidAppear(animated);
       StatusLabel.Text = string.Format("Server listening on\r\nhttp://{0}:8080", GetIPAddress ());
       WebServer.Start(8080);
     }
    
     public override void ViewDidDisappear (bool animated)
     {
       base.ViewDidDisappear(animated);
       WebServer.Stop();
     }
    

    And here are two app specific examples of request handlers

     class IndexActionHandler : DefaultActionHandler
     {
       public IndexActionHandler(HttpListenerRequest request)
         : base(request)
       {
       }
    
       public override ActionResult Execute()
       {
         var result = new HtmlResult();
         result.AppendLine("<html>");
         result.AppendLine("<body>");
         result.AppendLine("<h1>Upload an image</h1>");
         result.AppendLine("<form action='/Upload' enctype='multipart/form-data' method='post'>");
         result.AppendLine ("<input name='Image' type='file'/><br/>");
         result.AppendLine("<input name='Upload' type='submit' text='Upload'/>");
         result.AppendLine("</form>");
         result.AppendLine("</body>");
         result.AppendLine("</html>");
         return result;
       }
     }
    
     class UploadActionHandler : DefaultActionHandler
     {
       public UploadActionHandler(HttpListenerRequest request)
         : base(request)
       {
       }
    
       public override ActionResult Execute()
       {
         string errorMessage = null;
         var file = FormData.GetFile("Image");
         if (file == null 
           || file.FileData == null 
           || file.FileData.Length == 0 
           || string.IsNullOrEmpty(file.FileName))
           errorMessage = "No image uploaded";
    
         if (errorMessage == null)
           ProcessFile(file);
    
         var result = new HtmlResult();
         result.AppendLine("<html>");
         result.AppendLine("<body>");
         if (errorMessage == null)
           result.AppendLine("<h1>File uploaded successfully</h1>");
         else
         {
           result.AppendLine("<h1>Error</h1>");
           result.AppendLine("<h2>" + errorMessage + "</h2>");
         }
         result.AppendLine("</body>");
         result.AppendLine("</html>");
         return result;
       }
    
       void ProcessFile(MultiPartStreamFileValue postedFile)
       {
         string fileName = "Where to save the file";
         using (var fileStream = 
           new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
         {
           fileStream.Write(postedFile.FileData, 0, postedFile.FileData.Length);
         }
       }
     }
    

    You can download the source code here https://sites.google.com/site/mrpmorris/EmbeddedWebServerMT.zip

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a bunch of classes which I need to do serialize and deserialize from/to
Have a build process that can't be edited and need to pack another war
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
Have the following scenario. I have a few form, which essentially have a few
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
have a table that dynamically generates text boxes in run time. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.