Skip to content

Instantly share code, notes, and snippets.

@mksddn
Created November 12, 2023 14:38
Show Gist options
  • Select an option

  • Save mksddn/393c43b4713e28d887d0d4372c622f58 to your computer and use it in GitHub Desktop.

Select an option

Save mksddn/393c43b4713e28d887d0d4372c622f58 to your computer and use it in GitHub Desktop.

Revisions

  1. mksddn created this gist Nov 12, 2023.
    51 changes: 51 additions & 0 deletions soap_example.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    <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 -->