1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
import httplib, urllib
class PyXmlHttpPost:
def __init__(self):
self.buf = ""
self.host = "monsite.free.fr"
# usefull for string to hex encryption
def hex(self, text):
res = ""
n = len(text)
for i in range(n):
tmp = str(hex(ord(text[i])))
res += tmp[2:4]
return res
def load(self,filename):
# get file contents (binary read)
fd = open(filename,"rb")
self.buf = fd.read()
fd.close()
# Post XML data
def postData(self):
params = urllib.urlencode({'xml': self.buf})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = httplib.HTTPConnection(self.host)
conn.request("POST", "/monscript.php", params, headers)
response = conn.getresponse()
print response.status, response.reason
print response.read()
response.close() |
Partager