node.js - 如何在nodejs中向XML-WSDL中的服务发送请求
问题描述
我在 Web 服务(WSDL)中有一个 XML。该文件包含许多服务,我想向 Nodejs 中的该服务之一发送请求。但我对 XML 和 WSDL 一无所知。我只想请求服务并向其发送一些参数并获得响应。
这个 xml 服务包含一些这样的服务:
<wsdl:operation name="bpPaymentRequest">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="bpPayRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="bpPayRequestResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
我想向这项服务请求这样的事情:
const response = await axios.post( "https://example.com/services/pgw?bpPaymentRequest" , payReqParams)
但是,如果我对此进行测试,我知道这是错误的!我应该如何向该服务发送请求?
解决方案
It seems that you are willing to call a SOAP
web service from axios
.
SOAP web services talk XML
. That means they accept XML as input and return another XML as response. In contrast with Json APIs
, they do not accept JSON data input.
So,
- You need to prepare an XML for input
- Send it via
axios
- Parse the result assuming that is a valid XML
A sample code would be like this:
var xml ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\
xmlns:web="http://shaparak/">\
<soapenv:Header/>\
<soapenv:Body>\
<web:param>\
<web:amount>123</web:amount>\
</web:param>\
</soapenv:Body>\
</soapenv:Envelope>';
axios.post('https://example.com/services/pgw?bpPaymentRequest',
xml,
{headers:
{'Content-Type': 'text/xml'}
}).then(res=>{
console.log(res);
}).catch(err=>{console.log(err)});
Attention
Are you implementing a bank gateway for payments with Mellat or Shaparak? They have some implementation for Node.js.
推荐阅读
- javascript - Vercel (Zeit) 托管服务 - 为 REST 请求阻止 CORS
- html - 如何控制跨浏览器的 IFrame 行为?
- c++ - obj 向量到成员函数
- r - 单击 DTdatatable 中的单元格并移动到闪亮应用程序的另一个选项卡
- c++ - 将 std::memcpy 结构转换为 std::vector 是未定义的行为吗
那有足够的容量吗? - java - 我不能声明或使用 java swing 对象
- jquery - jQuery Validate:仅在表单成功验证后启用提交按钮
- kotlin - 确保主 JVM 程序会崩溃,即使使用 Kotlin Coroutines 启动也是如此
- javascript - 简化三元运算符
- azure - Ansible中模板内的模板?