Web Service系列之实例之使用urllib发送SOAP POST请求
2017-04-21 21:49
766 查看
原文链接: Web Service系列之实例之使用urllib发送SOAP POST请求
完整代码:
输出结果:
问题:
那么,
参数名(
名字空间
名字空间的值取自wsdl(如
如,
参数
参数名取自wsdl的
如,
完整代码:
import urllib.request url_jaxws = "http://localhost:9000/WS/HelloWorld" url_spyne = "http://localhost:8000/" data_jaxws = '''<?xml version='1.0' encoding='utf-8'?> <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:Body> <ns0:helloWorld xmlns:ns0="http://webservice.kylinux.com/"> <arg0>Kylin</arg0> <arg0>Shu</arg0> </ns0:helloWorld> </soap-env:Body> </soap-env:Envelope> ''' data_spyne = '''<?xml version='1.0' encoding='utf-8'?> <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:Body> <ns0:say_hello_plus2 xmlns:ns0="spyne.examples.hello.soap"> <ns0:name_plus> <ns0:string>Kylin</ns0:string> <ns0:string>Shu</ns0:string> </ns0:name_plus> </ns0:say_hello_plus2> </soap-env:Body> </soap-env:Envelope> ''' headers = {'Content-Type': 'text/xml'} req = urllib.request.Request(url_jaxws, data=data_jaxws.encode('utf-8'), headers=headers) res = urllib.request.urlopen(req) print(res.read().decode('utf-8')) req = urllib.request.Request(url_spyne, data=data_spyne.encode('utf-8'), headers=headers) res = urllib.request.urlopen(req) print(res.read().decode('utf-8'))
输出结果:
➜ websvr python3 ./invoke_ws.py <?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:helloWorldResponse xmlns:ns2="http://webservice.kylinux.com/"><return>Hello world from KylinShu</return></ns2:helloWorldResponse></S:Body></S:Envelope> <?xml version='1.0' encoding='UTF-8'?> <soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="spyne.examples.hello.soap"><soap11env:Body><tns:say_hello_plus2Response><tns:say_hello_plus2Result><tns:string>Kylin</tns:string><tns:string>Shu</tns:string></tns:say_hello_plus2Result></tns:say_hello_plus2Response></soap11env:Body></soap11env:Envelope>
问题:
那么,
data_jaxws和
data_spyne中的名字空间(
<ns0:say_hello_plus2 xmlns:ns0="spyne.examples.hello.soap">中的
spyne.examples.hello.soap)的值从哪里取呢?
参数名(
<ns0:string>Kylin</ns0:string>中的
string)的值又如何确定呢?
名字空间
名字空间的值取自wsdl(如
http://localhost:8000/?wsdl)的
<definitions>或
<wsdl:definitions>节点中
xmlns:tns或
targetNamespace的值
如,
xmlns:tns="spyne.examples.hello.soap" targetNamespace="spyne.examples.hello.soap"
参数
参数名取自wsdl的
<wsdl:types>节点
如,
<wsdl:types> <xs:schema targetNamespace="spyne.examples.hello.soap" elementFormDefault="qualified"> <xs:complexType name="stringArray"> <xs:sequence> <xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded" nillable="true"/> </xs:sequence> </xs:complexType> ... ... </xs:schema> </wsdl:types>
相关文章推荐
- Web Service系列之实例之使用http.client发送SOAP POST请求
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android-HTTP实例——使用GET方法、POST方法发送请求(安卓4.0以下版本)
- JAVA使用http发送post或get请求实例
- Android HTTP实例 使用GET方法和POST方法发送请求(通过Apache接口实现)
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求
- java使用POST发送soap报文请求webservice返回500错误解析
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求
- java使用POST发送soap报文请求webservice返回500错误解析
- 使用urllib发送post请求-模拟网站买票查票的post
- Android HTTP实例 使用GET方法和POST方法发送请求
- Python使用requests发送POST请求实例代码
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求