如何在javascript中使用soap [英] How to use soap in javascript
问题描述
我正在尝试在 javascript 中使用 SOAP,但我不知道如何启动它.这是我用 PHP 编写的代码示例,它运行良好.我想用 Javascript 编写这段代码.在下面的代码中,我从 www.example.com 调用了一个 api,为了调用某些 api,我们需要传递一些参数.
I am trying to use SOAP in javascript but i am not getting how to start it. Here is the code sample i write in PHP and it works fine. I want to write this code in Javascript. In following code i call one api from a www.example.com and for calling certain api we require to pass some parameters.
$soapClient = new SoapClient("https://www.example.com/WSDL");
$param_sh = array( );
$header = new SoapHeader('http://somesite.com/action/', 'user_credential', $param_sh);
$soapClient->__setSoapHeaders(array($header))
$param = array("with some parameter");
$contents = $soapClient->__call("name_of_method",array($param));
print($contents);
推荐答案
现在,自从提出这个问题 5 年多以来,Javascript 和 Web 总体上发生了很多事情,所以:
Now, after more than 5 years since this question was asked, lots of stuff has happened to Javascript and web in general, so:
您可以发送跨域请求,现代浏览器 100% 可以接受(当然,如果您发送请求的服务器允许 CORS)
you can send cross-origin requests and modern browsers are 100% OK with that (if the server you're sending them to allows CORS, of course)
there are lots of libraries both for server and client side javascript.
在 StackOverflow 上有很多关于该主题的问题.
there are lots of questions on the topic on StackOverflow.
这篇关于如何在javascript中使用soap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!