Help with POST request.
Chris Liechti
cliechti at gmx.net
Fri Mar 29 18:19:36 EST 2002
Gustavo Cordova <gcordova at hebmex.com> wrote in
news:mailman.1017440584.2947.python-list at python.org:
...
> Well, I'm having some trouble accepting POST requests.
...
> ==========================================================import
> BaseHTTPServer
>
> SIMPLE_WEB_FORM = """ ... a little web page in HTML ..."""
>
> class TestHTTPRequestHandler
(BaseHTTPServer.BaseHTTPRequestHandler):
> def test_response(self):
> # Always so positive.
> self.send_response(200)
> self.send_header("Content-type", "text/html")
> self.end_headers()
>
> def do_GET(self):
> self.test_response()
> self.wfile.write(SIMPLE_WEB_FORM)
>
> def do_POST(self):
> self.test_response()
> print "-" * 60
#find out length of input data
length = int(self.headers.getheader('content-length'))
#read data
print self.rfile.read(length)
> print "-" * 60
> self.wfile.write(SIMPLE_WEB_FORM)
>
> BaseHTTPServer.test(TestHTTPRequestHandler,
BaseHTTPServer.HTTPServer)
>
> ==========================================================
> OK, the problem is I can't ever see what's being sent via POST,
> it hangs when reading from the rfile object.
>
> I'd appreciate any and all comments.
i've replaced the read() above with a solution that works for me.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list