node.js - 在将 XML 发送到 SOAP API 之前,如何在我的 XML 中放置一些变量?
问题描述
我有以下代码,我终于能够使用 XML 并调用 SOAP api
import { EventPattern } from '@nestjs/microservices';
import { InjectModel } from '@nestjs/mongoose';
import { json } from 'express';
import { Model } from 'mongoose';
import { stringify } from 'querystring';
import * as soap from 'soap';
import { product } from './product/product.model';
import * as fs from 'fs';
import * as path from 'path';
import * as xml2js from 'xml2js';
@Controller()
export class AppController {
constructor(@InjectModel('product') private readonly productModel: Model<any>,) { }
@EventPattern("next")
async handleMessagePrinted(data: Record<any, any>) {
console.log(data);
console.log(data);
this.sendSoap(data);
}
insertproduct(data: any) {
stringify(data);
return this.productModel.insertMany(data);
}
sendSoap(product: any) {
let soapRequest = require('easy-soap-request');
// example data
let url = 'http://apisoap.com/product/';
let sampleHeaders = {
'user-agent': 'sampleTest',
'Content-Type': 'text/xml;charset=UTF-8',
'soapAction': '',
};
let xml = 'Createproduct.xml';
fs.readFile(xml, "utf-8", function(err, data) {
if (err) console.log(err);
// we log out the readFile results
// we then pass the data to our method here
xml2js.parseString(data, function(err, result) {
if (err) console.log(err);
// here we log the results of our xml string conversion
console.log("result: "+result);
});
});
// usage of module
let { response } = soapRequest({ url: url, headers: sampleHeaders, xml: xml, timeout: 1000 }); // Optional timeout parameter(milliseconds)
return response;
}
}
但现在我没有找到一种在将调用发送到 API 之前将一些变量放入该 XML 的方法。
我的最终目标是使用我收到的 JSON 中的一些变量并将它们放在 XML 的正确位置
解决方案
推荐阅读
- php - “已经为此令牌创建了成功的计费协议。”
- javascript - 如何从外部链接导航到引导程序 4 的特定选项卡
- ffi - 尝试创建绑定的访问器名称冲突
- hibernate - 由带有 LazyNoProxy 注释的 JoinColumns 映射的实体的提取不适用于标准查询 - 导致 n + 查询
- javascript - 如何使用图片点击事件
- swift - 如何使用快速编码根据特定的排序顺序对自定义对象进行排序
- url - 如何使用带有“单击此处”标签的 pdfbox 在 pdf 中插入 URL 以重定向到网站?
- caching - 什么样的大数据框架可以实现毫秒级的数据转换?
- java - 转换设置
列出 在java中? - hive - 在创建表中无法识别列规范时间戳