您的位置:首页 > 理论基础 > 计算机网络

soap HTTP 调用

2014-05-05 10:05 274 查看
1、通过soapui 查看调用的代码
</pre><pre code_snippet_id="371258" snippet_file_name="blog_20140531_3_2326006" name="code" class="python">
2、调用的python代码
def call_soap_with_http(url,send_msg):
    import httplib
    import urllib
    import urlparse
    url_info = urlparse.urlparse(url)
    host,port = url_info.netloc.split(":")
    path = url_info.path
    
    conn = httplib.HTTPConnection(host,port)
    headers = {"Content-Type":"text/xml; charset=utf-8",
               "Content-Length":"%d" % len(send_msg),
               "SOAPAction":"\"\""}
            
    conn.request("POST", path, '', headers)
    conn.send(send_msg)
    ret = conn.getresponse().read()
    return ret


3、调用类似如下:

      

url="http://xxx.xxx.xxx.xxx/services/test_services"
msg = u"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ui="http://ui.server.pointquery.vas.soap.interfaces.lcsmp.linkage.com" xmlns:req="http://req.ui.server.tst.vas.soap.interfaces.lcsmp.linkage.com">
<soapenv:Header/>
<soapenv:Body>
<ui:test>
<ui:req>
<req:arg1>?</req:arg1>
</ui:req>
</ui:test>
</soapenv:Body>
</soapenv:Envelope>
"""
result = call_soap_with_http(url,msg)
print result
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: