最简单的SOAP示例 [英] Simplest SOAP example
本文介绍了最简单的SOAP示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Javascript的最简单的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
推荐答案
这是最简单的JavaScript SOAP客户端我可以创造。
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('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屋!
查看全文