Upload text file?
fredrik at pythonware.com
Wed Aug 14 12:03:03 CEST 2002
Gustaf Liljegren wrote:
> I'm looking for a general way to have a CGI script fetch the whole body of
> an HTTP POST request and put in a variable. It sounds so simple, but I've
> only found solutions for more complex problems, involving forms and binary
> files. Here's my POST request:
> POST /cgi-bin/test.py HTTP/1.1
> Host: 127.0.0.1
> Accept: */*
> Connection: close
> Hello world!
> So it's the "Hello world!" I want in a variable...
variable = sys.stdin.read()
bytes = int(os.environ.get("CONTENT_LENGTH", 0))
if bytes > MAX_REQUEST_SIZE:
giveup("request too large")
variable = sys.stdin.read(bytes)
More information about the Python-list