Skip to content

Instantly share code, notes, and snippets.

@katylava
Created April 22, 2016 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katylava/d1aff55b00e488341ed389732bbb10bc to your computer and use it in GitHub Desktop.
Save katylava/d1aff55b00e488341ed389732bbb10bc to your computer and use it in GitHub Desktop.
var fs = require('fs');
var request = require('request');
request.post({ body: "^xa^cfa,50^fo100,100^fdHello World^fs^xz", encoding: null, url: 'http://api.labelary.com/v1/printers/8dpmm/labels/4x6.75/0/' }, function(err, resp, body) {
if (err) {
return console.log(err);
}
console.log('headers', resp.headers);
console.log('status', resp.statusCode);
console.log('body', body);
if (body.length < 1000) {
console.log(new Buffer(body).toString());
}
fs.writeFile('./label.png', body, function(err) {
if (err) {
console.log(err);
}
});
});
@katylava
Copy link
Author

console output:

headers { 'access-control-allow-origin': '*',
  'content-type': 'text/plain',
  date: 'Fri, 22 Apr 2016 16:48:42 GMT',
  'x-vcap-request-id': '5c702169-4c85-4a89-69e2-c4aa06429a70',
  'content-length': '38',
  connection: 'Close' }
status 415
body <Buffer 45 52 52 4f 52 3a 20 48 54 54 50 20 34 31 35 20 55 6e 73 75 70 70 6f 72 74 65 64 20 4d 65 64 69 61 20 54 79 70 65>
ERROR: HTTP 415 Unsupported Media Type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment