Returning HTTP POST body from CGI module
shriek at gmx.co.uk
Mon Nov 26 01:55:49 CET 2001
> > I have a Python CGI script receiving XML data via HTTP POST from
> > another company. Unfortunately, that company doesn't seem to
> > have implemented the HTTP protocol correctly.
> This is completely valid HTTP. They probably ought to have
> Content-Type header in there, but it's no big deal.
Thank you for putting me straight on this one. Since web browsers
seem to send urllib.quote_plus()'ed text, I guess that the web server
is urllib.unquote()'ing everything it receives. So, whether you send
quoted or unquoted text it will become the same thing.
> CGI request content comes in on stdin. The cgi lib just
> parses it. The headers tend to show up in the environment,
> but I'm not sure any old header you send shows up
> The following program should give you access to the data though:
> import sys, os
> length = os.environ["CONTENT_LENGTH"]
> print sys.stdin.read(length)
Excellent, works a treat ~ using sys.stdin.read(int(length)) ~ and
thanks for explaining how CGI request content is transfered via stdin.
I had been wondering how the data was transfered to Apache.
More information about the Python-list