# http_post.py # # HTTP POST file using "application/x-www-form-urlencoded" content type. # import httplib import StringIO import base64 host = '' path = '' fn = 'post.txt' debug = 0 # grab file contents and size f = open( fn, 'rb' ) b = StringIO.StringIO( f.read() ) f.close() s = len( b.getvalue() ) # send file h = httplib.HTTPConnection( host ) h.set_debuglevel( debug ) h.putrequest( 'POST', path, True, True ) h.putheader( 'Content-Length', str(s) ) h.putheader( 'Host', host ) h.putheader( 'Content-type', 'application/x-www-form-urlencoded' ) h.endheaders() h.send( b.getvalue() ) r = h.getresponse() # print reply print "%s %s" % ( r.status, r.reason ) print print r.read() print h.close()