Problems with POST
jdavis at empires.org
Sun Feb 24 15:44:22 EST 2002
Can you run the second script as a cgi and load it with a web browser to
determine which script is not behaving correctly? I have a suspicion that
the first script is somehow not posting quite correctly.
Sunit Joshi wrote:
> Somehow I can't seem to get any data with POST although the same
> script (with modifications in the first one) works for GET . Here's
> the scripts: First one is to POST and next one to recieve the POSTED
> #!C:\Python21\Python.exe -u
> #To POST and output the data - postTest.py
> from httplib import HTTP
> from urllib import quote
> quoteData = "Sunit Joshi"
> postData = 'txtName=' + quote(quoteData)
> print 'Will POST ', len(postData), 'bytes:', postData
> # begin HTTP request
> req = HTTP('sunitw2k:6080')
> req.putrequest("POST" ,'/PyCgi/formTest.py')
> req.putheader("Accept", "text/html")
> req.putheader("User-Agent", "postTest.py")
> # Set Content-length to length of PostData
> req.putheader("Content-length", str(len(postData)))
> # Send POST data after ending headers
> replycode, message, headers = req.getreply()
> print "HTTP RESPONSE: ", replycode, message
> print 'HEADERS: ', str(headers)
> # Get file-like object from HTTP response
> # and print received HTML to screen.
> fd = req.getfile()
> txtlines = fd.read()
> print '\nReceived following HTML:\n'
> print txtlines
> #!c:\Python21\Python.exe -u
> # To send the data posted - formTest.py
> import sys
> import cgi
> sys.stderr = sys.stdout
> form = cgi.FieldStorage()
> print "Content-type: text/html"
> if not form:
> print "<h2>Field 'txtName' not filled in.</h2>"
> print str(form)
> print '<h3>You entered <font color="#FF6600">%s</font></h3>' %
More information about the Python-list