Monday 20 August 2007

Http POST handling using System.Net.HttpListener in IronPython

Sorry for longish title, but I feel that this post should be googlable. I happened to spend just too much time looking for this recently. In case you don't know how HttpListener works, I suggest reading this tutorial. If you are interested only in POST handling, here's the snippet:


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

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

# nameValuePairs contains now
# a dictionary-like object ready for further processing

2 comments:

trampi said...
This comment has been removed by the author.
trampi said...

You are my hero! I searched the last hour for something like this.