javascript - 如何使用 axios 在 PrintNode.js 中打印?示例代码
问题描述
所以在搜索了很长时间之后,我想分享我的代码。此代码旨在使用 Javascript 或 Node.js 从浏览器静默打印 ZPL(斑马打印机)标签。
首先使用 NPM 安装 axios。
然后复制这段代码
const axios = require("axios");
var dataprint = "DATA HERE!!!";
async function makeGetRequest() {
let payload = {
printerId: "Printer ID(login in Printnode here you can find the id of your printer)",
title: "test print job",
contentType: "raw_base64",
content: dataprint,
source: "pack",
};
let res = await axios.post(
"https://api.printnode.com/printjobs",
payload,
{
auth: {
username: "API key. Find it on printnode website",
password: "",
},
}
);
let data = res.data;
console.log(data);
}
makeGetRequest();
希望我可以用这段代码帮助一些人!在评论中告诉我