axios.post(url, xml, options)
.then(response => {
// convert XML response to JSON and return
xml2js.parseString(response.data, (err, result) => {
console.log(JSON.stringify({result}));
“结果”:{ “retrieveDocumentResponse”:{ “响应”:[{ “数据源”:[ “UEsDBBQABgAIAAAAIQBi7p1oXgEAAJAEAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ==”], “扩展”:[ “XLSX”], “文件名”:[“{947E115A- 34A3-4281-9160-A11AD16F63C9}“]” mimeType“:[” application / vnd.openxmlformats-officedocument.spreadsheetml.sheet“],” pageCountForDocument“:[” 0“]}]}}}
<<注意:实际的“数据源”有很多行>>
import base64 from "base64-utf8";
import utf8 from "utf8";
let buffer1 = new Buffer(JSON.stringify(result.retrieveDocumentResponse.response[0].datasource[0]));
let buffer2 = base64.decode(buffer1);
let buffer = utf8.encode(buffer2)
console.log(`Decoded data is ${buffer}`)
<<从console.log $ {buffer},我希望看到xls文件的内容。请参见“结果”中的“ mimeType”。却什么也没显示>>
我尝试使用几种方法从结果中解码“数据源”。我在做完全错误的事情吗?有一次它说它不是有效的Base64格式
var Base64Ron = require('@ronomon/base64');
var URLSafeBase64 = require('urlsafe-base64');
var Base64js = require('js-base64').Base64;
var base64All = require('base-64');
var unidecode = require('unidecode');