There is an issue which I cannot explain - the method described earlier works fine for GET requests, but the POST requests are always empty.
My understanding is that in the case of POST, the data are passed to the STDIN, so I need to read from this source.
The script:
#!/usr/bin/python
from mod_python import apache
from mod_python import util
import sys
def index(req):
raw = sys.stdin.read(5)
return """<html><body>foo bar %s </body></html>""" % (raw)
I use this to test it
import httplib, urllib
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
print params
conn = httplib.HTTPConnection(MYHOST)
conn.request("POST", MYURL, params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
The server responds with 200 OK, but
raw remains empty, even though I was expecting to see 5 bytes read from STDIN.
Is this improper use of the functions? Or can it be explained by an issue with the settings in httpd.conf?