Handling POST with HttpListener

If you want a longer introduction to System.Net.HttpListener, then visit Simple Server. This recipe (by Konrad), shows how to handle POST requests when writing servers using the HttpListener.

from System.IO import StreamReader from System.Web import HttpUtility

body = context.Request.InputStream encoding = context.Request.ContentEncoding reader = StreamReader(body, encoding) nameValuePairs = HttpUtility.ParseQueryString(reader.ReadToEnd, encoding)
 * 1) Having HttpListenerContext in context


 * 1) nameValuePairs contains now
 * 2) a dictionary-like object ready for further processing

HttpUtility.ParseQueryString parses the query string (the body of the post) from the request, into name-value pairs.

Back to Contents.