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.
相关问题
- Laravel Option Select - Default Issue
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
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
And here are two app specific examples of request handlers
You can download the source code here https://sites.google.com/site/mrpmorris/EmbeddedWebServerMT.zip
The main thing to understand is that HttpListener is a low level tool to work with http requests. All post data is in HttpListenerRequest.InputStream stream. Suppose we have a form like that:
Now we want to see the post data. Lets implement a method to do this:
upload some file and see result:
Next suppose we have simple form without uploading files:
Let's see the output:
Combined form result:
As you can see in case of simple form you can just read InputStream to string and parse post values. If there is a more complex form - you need to perform more complex parsing but it's still can be done. Hope this examples will save your time. Note, that is not always the case to read all stream as a string.