网上查询均说不行,捣鼓了一天,总算有些眉目。
import http.client
soap_body='''<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">
http://www.xxx.com/ISHWS/ChkReg
</a:Action><a:MessageID>urn:uuid:82989341-5861-49a4-bb93-c5edb9ec1497</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">
http://www.xxx.com/SHWS/SHWS.svc/SHWS
</a:To></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ChkReg xmlns="http://www.xxx.com"><RegParem>
<strRegInfoValue xmlns="http://schemas.datacontract.org/2004/07/SHWS">函数参数</strRegInfoValue>
<strUserValue xmlns="http://schemas.datacontract.org/2004/07/SHWS">函数参数</strUserValue>
</RegParem></ChkReg>
</s:Body></s:Envelope>'''
#楼上Fiddle抓包来的
soap_body=soap_body.replace("\n", "").replace("\r","") #去除字符串中的回车换行
#楼下xx.xx.xx.xx 为IP地址
ws=http.client.HTTPConnection("xx.xx.xx.xx")
ws.putrequest("POST","/SHWS/SHWS.svc/SHWS","HTTP/1.1")
ws.putheader("Host","xx.xx.xx.xx")
ws.putheader("Content-Type","application/soap+xml; charset=utf-8")
ws.putheader("Content-Length",len(soap_body))
ws.endheaders()
ws.send(soap_body.encode())
wr = ws.getresponse()
for i in wr:
print(i)
#总结:1、调用的函数及其参数都在SOAP中,构造相应字符串POST过去,然后获取响应数据即可实现。
#2、还可进一步封装,那串uuid没用。
#3、wsHttpBinding仍为明文