且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

最简单的 SOAP 示例

更新时间:2022-10-16 12:28:01

这是我能创建的最简单的 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();"/>