I would like some help on parsing HTTP POST requests in a C# console application. The app runs a 'web-server' using Owin. Details of the application are available here and the current 'stable version' of the relevant code is here.
I am extending the above application to enable configuration through the web UI. For example, the app currently reports a large number of parameters. I would like the end-user to be able to select which parameters get reported over the network. Towards this, I made some modifications to the code above:
using Microsoft.Owin;
using Owin;
.........
[assembly: OwinStartup(typeof(SensorMonHTTP.WebIntf))]
.........
.........
namespace SensorMonHTTP
{
...
public class WebIntf
{
public void Configuration(IAppBuilder app)
{
app.Run(context =>
{
var ConfigPath = new Microsoft.Owin.PathString("/config");
var ConfigApplyPath = new Microsoft.Owin.PathString("/apply_config");
var SensorPath = new Microsoft.Owin.PathString("/");
if (context.Request.Path == SensorPath)
{
return context.Response.WriteAsync(GetSensorInfo());
/* Returns JSON string with sensor information */
}
else if (context.Request.Path == ConfigPath)
{
/* Generate HTML dynamically to list out available sensor
information with checkboxes using Dynatree: Tree3 under
'Checkbox & Select' along with code to do POST under
'Embed in forms' in
http://wwwendt.de/tech/dynatree/doc/samples.html */
/* Final segment of generated HTML is as below:
<script>
.....
$("form").submit(function() {
var formData = $(this).serializeArray();
var tree = $("#tree3").dynatree("getTree");
formData = formData.concat(tree.serializeArray());
// alert("POST this:\n" + jQuery.param(formData));
// -- This gave the expected string in an alert when testing out
$.post("apply_config", formData);
return true ;
});
......
</script></head>
<body>
<form action="apply_config" method="POST">
<input type="submit" value="Log Selected Parameters">
<div id="tree3" name="selNodes"></div>
</body>
</html>
End of generated HTML code */
}
else if (context.Request.Path == ConfigApplyPath)
{
/* I want to access and parse the POST data here */
/* Tried looking into context.Request.Body as a MemoryStream,
but not getting any data in it. */
}
}
}
........
}
Can anyone help me with how the POST data can be accessed in the above code structure?
Thanks in advance!