其实原理就是根据webservice协议指定的request的soap格式,用http post的method把参数传递过去就算是调用了,然后解析返回的soap就可以了
鉴于网上python3.x 的http post 实现代码比较少,我贴一段:
def InvokeWebservice(phone,msg):
texturl='http://127.0.0.1:7789/SMSService.asmx?op=SendShortMessage'
postcontent='<?xml version="1.0" encoding="utf-8"?>'
postcontent+='<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/">'
postcontent+='<soap:Body>'
postcontent+='<SendShortMessage xmlns="http://tempuri.org/">'
postcontent+='<phonenum>'+phone+'</phonenum>'#参数
postcontent+='<message>'+msg+'</message>'#参数
postcontent+='</SendShortMessage>'
postcontent+='</soap:Body>'
postcontent+='</soap:Envelope>'
req=urllib.request.Request(texturl,data=postcontent.encode('utf-8'),headers={'Content-Type': 'text/xml'})
urllib.request.urlopen(req)
本文详细介绍了如何使用Python3.x通过HTTP POST方法调用WebService,并解析返回的SOAP响应的过程。提供了具体的代码示例,帮助开发者轻松实现与WebService的交互。
775

被折叠的 条评论
为什么被折叠?



