I am new to Node Js and trying to make a rest call from Node Js.
I am basically trying to convert a front end Ajax call into a back-end NodeJs call.
Here is the Ajax.
$.ajax({url: 'https://192.168.0.14:3000/printer',
type: 'post',
data:'^XA^FO50,50^GFA,1518,1518,23,L03IF,K03FC1FF,3FFJ01NF^FS^XZ',
success: function(d) {
alert(d);
}
});
}
Unfortunately I am stuck without the ability to send Data field. I can't change the other end of API as it is a firmware in a printer.
Here is my failed backend code so far:
I am new to Node Js
var options = {
body: '^XA^FO50,50^GFA,1518,1518,23,L03IF,K03FC1FF,K0F8I07C,J03CK0F,J0FCK0FC,I03FCK0FF,I07FCK07F8,I0FF8K07FC,001EF8K078E,003878K0703,0060380IF07018,00C6383KF00C,019E301KF006,033CI0KF803,033CI0KF881,0678I07JFC718,0E7J07IFE038C,0CEJ07IFC018C,1CK07IF8100E,1CK07IF1380E^FS^XZ',
host: '192.168.0.12',
path: '/pstprnt',
method: 'POST',
json: false,
data: '^XA^FO50,50^GFA,1518,1518,23,L03IF,K03FC1FF,K0F8I07C,J03CK0F,J0FCK0FC,I03FCK0FF,I07FCK07F8,^FS^XZ',
formData: '^XA^FO50,50^GFA,1518,1518,23,L03IF,K03FC1FF,K0F8I07C,J03CK0F,J0FCK0FC,I03FCK0FF,I07FCK07F8,I0FF8K07FC,^FS^XZ',
};
http.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
}).end();