最简单的 SOAP 示例 [英] Simplest SOAP example
本文介绍了最简单的 SOAP 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Javascript 的最简单的 SOAP 示例是什么?
为了尽可能有用,答案应该:
- 实用(换句话说,实际工作)
- 至少发送一个可以在代码其他地方设置的参数
- 至少处理一个可以在代码其他地方读取的结果值
- 使用大多数现代浏览器版本
- 尽可能简洁明了,不使用外部库
解决方案
这是我能创建的最简单的 JavaScript SOAP 客户端.
<头><title>SOAP JavaScript 客户端测试</title><script type="text/javascript">功能肥皂(){var xmlhttp = new XMLHttpRequest();xmlhttp.open('POST', 'https://somesoapurl.com/', true);//构建 SOAP 请求无功 sr ='<?xml version="1.0" encoding="utf-8"?>'+'<soapenv:信封' +'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'+'<soapenv:Body>'+'<api:some_api_call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+'<username xsi:type="xsd:string">login_username</username>'+'<password xsi:type="xsd:string">密码</password>'+'</api:some_api_call>'+'</soapenv:Body>'+'</soapenv:信封>';xmlhttp.onreadystatechange = 函数 () {如果(xmlhttp.readyState == 4){如果(xmlhttp.status == 200){警报(xmlhttp.responseText);//alert('done.use firebug/console to see network response');}}}//发送POST请求xmlhttp.setRequestHeader('Content-Type', 'text/xml');xmlhttp.send(sr);//发送请求//...}头部><身体><form name="Demo" action="" method="post"><div><input type="button" value="Soap" onclick="soap();"/>
</表单>