最简单的 SOAP 示例 [英] Simplest SOAP example

查看:27
本文介绍了最简单的 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();"/>

</表单><!-- 错别字-->

What is the simplest SOAP example using Javascript?

To be as useful as possible, the answer should:

  • Be functional (in other words actually work)
  • Send at least one parameter that can be set elsewhere in the code
  • Process at least one result value that can be read elsewhere in the code
  • Work with most modern browser versions
  • Be as clear and as short as possible, without using an external library

解决方案

This is the simplest JavaScript SOAP Client I can create.

<html>
<head>
    <title>SOAP JavaScript Client Test</title>
    <script type="text/javascript">
        function soap() {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'https://somesoapurl.com/', true);

            // build SOAP request
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<soapenv:Envelope ' + 
                    '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</password>' +
                        '</api:some_api_call>' +
                    '</soapenv:Body>' +
                '</soapenv:Envelope>';

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        alert(xmlhttp.responseText);
                        // alert('done. use firebug/console to see network response');
                    }
                }
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);
            // send request
            // ...
        }
    </script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="soap();" />
        </div>
    </form>
</body>
</html> <!-- typo -->

这篇关于最简单的 SOAP 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆