Javascript 从nodejs调用SOAP API并使用(json)响应数据
我从POSTMAN调用了一个SOAP API,它工作正常。现在我想将它与Node.js(nextjs)一起使用。 这就是我调用API的方式,也是我得到的。 我将如何调用它并获得json响应? 现在我这样打电话-Javascript 从nodejs调用SOAP API并使用(json)响应数据,javascript,node.js,xml,api,soap,Javascript,Node.js,Xml,Api,Soap,我从POSTMAN调用了一个SOAP API,它工作正常。现在我想将它与Node.js(nextjs)一起使用。 这就是我调用API的方式,也是我得到的。 我将如何调用它并获得json响应? 现在我这样打电话- const xml = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:x
const xml =
"<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><HourlyTransactions xmlns='https://secure.myterminals.com/ConfigStatusSyncService'><StartTime>2020-12-17 00:00</StartTime><EndTime>2020-12-18 00:00</EndTime><Login></Login><Password></Password></HourlyTransactions></soap:Body></soap:Envelope>";
let res = await fetch(
"https://secure.myterminals.com/ConfigStatusSyncService/DataQuery.asmx",
{
method: "POST",
headers: { "Content-Type": "text/xml" },
body: xml,
}
);
console.log(res);
constxml=
"2020-12-17 00:002020-12-18 00:00";
让res=等待取回(
"https://secure.myterminals.com/ConfigStatusSyncService/DataQuery.asmx",
{
方法:“张贴”,
标题:{“内容类型”:“text/xml”},
正文:xml,
}
);
控制台日志(res);
我希望这能帮助我使用easey soap请求,下面是一个示例
import soapRequest from "easy-soap-request";
const url = "https://my-soap-server";
const sampleHeaders = {
"Content-Type": "text/xml;charset=UTF-8",
SOAPAction: "https://my-soap-action/something"
};
const xml = `<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<HourlyTransactions xmlns='https://secure.myterminals.com/ConfigStatusSyncService'>
<StartTime>2020-12-17 00:00</StartTime><EndTime>2020-12-18 00:00</EndTime><Login></Login><Password></Password></HourlyTransactions>
</soap:Body>
</soap:Envelope>`;
async function makeRequest() {
const { response } = await soapRequest({
url: url,
headers: sampleHeaders,
xml: xml,
timeout: 1000
});
const { headers, body, statusCode } = response;
console.log(headers);
console.log(body);
console.log(statusCode);
document.body.innerHTML = body;
}
makeRequest();
从“easy soap request”导入soap请求;
常量url=”https://my-soap-server";
常量采样头={
“内容类型”:“text/xml;charset=UTF-8”,
SOAPAction:“https://my-soap-action/something"
};
常量xml=`
2020-12-17 00:002020-12-18 00:00
`;
异步函数makeRequest(){
const{response}=等待soapRequest({
url:url,
标题:示例标题,
xml:xml,
超时:1000
});
const{headers,body,statusCode}=响应;
console.log(头文件);
控制台日志(主体);
console.log(状态码);
document.body.innerHTML=body;
}
makeRequest();
这是我找到的示例我希望这能帮助我使用easey soap请求,下面是一个示例
import soapRequest from "easy-soap-request";
const url = "https://my-soap-server";
const sampleHeaders = {
"Content-Type": "text/xml;charset=UTF-8",
SOAPAction: "https://my-soap-action/something"
};
const xml = `<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<HourlyTransactions xmlns='https://secure.myterminals.com/ConfigStatusSyncService'>
<StartTime>2020-12-17 00:00</StartTime><EndTime>2020-12-18 00:00</EndTime><Login></Login><Password></Password></HourlyTransactions>
</soap:Body>
</soap:Envelope>`;
async function makeRequest() {
const { response } = await soapRequest({
url: url,
headers: sampleHeaders,
xml: xml,
timeout: 1000
});
const { headers, body, statusCode } = response;
console.log(headers);
console.log(body);
console.log(statusCode);
document.body.innerHTML = body;
}
makeRequest();
从“easy soap request”导入soap请求;
常量url=”https://my-soap-server";
常量采样头={
“内容类型”:“text/xml;charset=UTF-8”,
SOAPAction:“https://my-soap-action/something"
};
常量xml=`
2020-12-17 00:002020-12-18 00:00
`;
异步函数makeRequest(){
const{response}=等待soapRequest({
url:url,
标题:示例标题,
xml:xml,
超时:1000
});
const{headers,body,statusCode}=响应;
console.log(头文件);
控制台日志(主体);
console.log(状态码);
document.body.innerHTML=body;
}
makeRequest();
这是我发现的示例我宁愿使用easy soap请求包。 下面是一个工作示例:
const soapRequest = require('easy-soap-request');
const url = 'https://secure.myterminals.com/ConfigStatusSyncService/DataQuery.asmx';
const sampleHeaders = {
'Content-Type': 'text/xml',
// 'soapAction': '' //FILL_HERE If Needed
};
const xmlSoapEnvelope = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><HourlyTransactions xmlns='https://secure.myterminals.com/ConfigStatusSyncService'><StartTime>2020-12-17 00:00</StartTime><EndTime>2020-12-18 00:00</EndTime><Login></Login><Password></Password></HourlyTransactions></soap:Body></soap:Envelope>";
(async () => {
try {
const {
response
} = await soapRequest({
url: url,
headers: sampleHeaders,
xml: xmlSoapEnvelope,
timeout: 1000
});
const {
headers,
body,
statusCode
} = response;
console.log('soap headers:', headers);
console.log('soap body:', body);
}
catch(e) {
console.log("Error Due to: ", e)
}
})()
const soapRequest=require('easy-soap-request');
常量url=https://secure.myterminals.com/ConfigStatusSyncService/DataQuery.asmx';
常量采样头={
“内容类型”:“text/xml”,
//“soapAction”:“”//如果需要,请在此处填写
};
const xmlsoapevelope=“2020-12-17 00:002020-12-18 00:00”;
(异步()=>{
试一试{
常数{
响应
}=等待soapRequest({
url:url,
标题:示例标题,
xml:xmlsoapevelope,
超时:1000
});
常数{
标题,
身体,
状态码
}=响应;
log('soap头:',头);
log('soap body:',body);
}
捕获(e){
log(“由于:,e而导致的错误”)
}
})()
我宁愿使用easy soap请求包。
下面是一个工作示例:
const soapRequest = require('easy-soap-request');
const url = 'https://secure.myterminals.com/ConfigStatusSyncService/DataQuery.asmx';
const sampleHeaders = {
'Content-Type': 'text/xml',
// 'soapAction': '' //FILL_HERE If Needed
};
const xmlSoapEnvelope = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><HourlyTransactions xmlns='https://secure.myterminals.com/ConfigStatusSyncService'><StartTime>2020-12-17 00:00</StartTime><EndTime>2020-12-18 00:00</EndTime><Login></Login><Password></Password></HourlyTransactions></soap:Body></soap:Envelope>";
(async () => {
try {
const {
response
} = await soapRequest({
url: url,
headers: sampleHeaders,
xml: xmlSoapEnvelope,
timeout: 1000
});
const {
headers,
body,
statusCode
} = response;
console.log('soap headers:', headers);
console.log('soap body:', body);
}
catch(e) {
console.log("Error Due to: ", e)
}
})()
const soapRequest=require('easy-soap-request');
常量url=https://secure.myterminals.com/ConfigStatusSyncService/DataQuery.asmx';
常量采样头={
“内容类型”:“text/xml”,
//“soapAction”:“”//如果需要,请在此处填写
};
const xmlsoapevelope=“2020-12-17 00:002020-12-18 00:00”;
(异步()=>{
试一试{
常数{
响应
}=等待soapRequest({
url:url,
标题:示例标题,
xml:xmlsoapevelope,
超时:1000
});
常数{
标题,
身体,
状态码
}=响应;
log('soap头:',头);
log('soap body:',body);
}
捕获(e){
log(“由于:,e而导致的错误”)
}
})()