直接用Qt写soap
原理
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtNetwork import *
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self._http = None
self.test()
def test(self):
http = QHttp('10.88.104.158')
self._http = http
data = '''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<UserLogin xmlns="http://www.richfit.com/">
<userLoginName>admin</userLoginName>
<userPwd>123</userPwd>
<appType>test</appType>
</UserLogin>
</soap:Body>
</soap:Envelope>'''
req = QHttpRequestHeader()
req.setRequest('POST', '/3DWebGIS/Services/DataService.asmx')
req.setValue('Host', '10.88.104.158')
req.setValue('Content-Type', 'text/xml; charset=utf-8')
req.setValue('Content-Length', str(len(data)))
req.setValue('SOAPAction', '"http://www.richfit.com/UserLogin"')
self.connect(self._http, SIGNAL('requestFinished(int, bool)'), self.finish)
cnt = data.encode('utf-8')
print http.request(req, cnt)
def test1(self):
import sys, httplib
data = '''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<UserLogin xmlns="http://www.richfit.com/">
<userLoginName>admin</userLoginName>
<userPwd>123</userPwd>
<appType>test</appType>
</UserLogin>
</soap:Body>
</soap:Envelope>'''
h = httplib.HTTP('10.88.104.158')
h.putrequest('POST', '/3DWebGIS/Services/DataService.asmx')
h.putheader('Host', '10.88.104.158')
h.putheader('User-Agent', 'Python post')
h.putheader('Content-Type', 'text/xml; charset="UTF-8"')
h.putheader('Content-length', str(len(data)))
h.putheader('SOAPAction', '"http://www.richfit.com/UserLogin"')
h.endheaders()
h.send(data)
sc, sm, header = h.getreply()
print sc, sm
print header
print h.getfile().read()
def finish(self, iid, ok):
print iid, ok
resp = self._http.lastResponse()
print resp.statusCode(), resp.reasonPhrase()
print str(self._http.readAll()).decode('utf-8')
app = QApplication(sys.argv)
frm = MainWindow()
frm.show()
app.exec_()
h = httplib.HTTP('10.88.104.158')