SOAP Despatcher

From PeformIQ Upgrade
Revision as of 08:12, 3 April 2009 by PeterHarding (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Python HTTPLIB version

$ cat desp_02.py 
#!/usr/bin/env python

import os
import binascii
import httplib
import urllib

from copy import copy

#-------------------------------------------------------------------------------

post_data = urllib.urlencode({'spam': 1, 'eggs': 2})

#   "Content-type" : "application/x-www-form-urlencoded",

#-------------------------------------------------------------------------------

post_headers = {
   'Content-type'    : 'text/xml;charset=UTF-8',
   'SOAPAction'      : '',
   'User-Agent'      : 'Jakarta Commons-HttpClient/3.0.1',
   'Host'            : 'hx403'
}


payload_constants = (13, 21110, 603010230)

# post_data = {}

# ue_post_data = urllib.urlencode(post_data)

#-------------------------------------------------------------------------------

payload_template = """<?xml version="1.0" encoding="UTF-8"?>
<XXXX xmlns="http://www.performiq.com.au/xml/soap">
...
</XXXX>"""

#-------------------------------------------------------------------------------

soap_env = """<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:epar="http://www.performiq.com.au/submit">
<soapenv:Header/>
<soapenv:Body>
<epar:submitManifestForDespatch soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<string xsi:type="xsd:string"><![CDATA[%s]]></string></epar:submitManifestForDespatch></soapenv:Body>
</soapenv:Envelope>"""


#-------------------------------------------------------------------------------

cookie  = binascii.b2a_base64("xxxxx:xxxxx")[:-1]

print '[%s]' % cookie

headers = copy(post_headers)

headers['Authorization']  = 'Basic %s' % cookie
headers['Content-Length'] = len(post_data)

print headers

DO    = 'POST'
URL   =  '/submit/method_service'
HOST  = 'HOST'

manifest = payload_template % payload_constants

print manifest

post_data = soap_env % manifest

print post_data

#-------------------------------------------------------------------------------

conn  = httplib.HTTPConnection(HOST)

conn.request(DO, URL, post_data_01, headers)

response = conn.getresponse()

print response.status, response.reason

data = response.read()

print data

conn.close()

#-------------------------------------------------------------------------------