If I correct the variable names in the example I get this program:

import httplib, urllib
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
h = httplib.HTTP("localhost:80")
h.putrequest("POST", "/cgi-bin/query")
h.putheader("Content-length", "%d" % len(params))
h.putheader('Accept', 'text/plain')
h.putheader('Host', 'www.musi-cal.com')
h.endheaders()
h.send(params)
reply, msg, hdrs = h.getreply()
# print errcode # should be 200
data = h.getfile().read() # get the raw HTML

It generates this HTTP request:

POST /cgi-bin/query HTTP/1.0
Content-length: 21
Accept: text/plain
Host: www.musi-cal.com

spam=1&eggs=2&bacon=0

Is this incorrect?

I use a little hacky program to see the request: 

import SocketServer

class MyServer(SocketServer.BaseRequestHandler):
    def handle(self):
        data = 1
        print "----------------------"
        while data:
            data = self.request.recv(10000)
            print data
        print "----------------------"
        self.request.send("ABC")

server = SocketServer.TCPServer(('127.0.0.1', 80), MyServer)
server.handle_request()


-- 
Python:
    Programming the way
    Guido
    indented it.
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython

Reply via email to