http - Using Pastebin API in Node.js -
i've been trying post paste pastebin in node.js, appears i'm doing wrong.
i'm getting bad api request, invalid api_option, i'm setting api_option paste documentation asks for.
var http = require('http'); var qs = require('qs'); var query = qs.stringify({ api_option: 'paste', api_dev_key: 'xxxxxxxxxxxx', api_paste_code: 'awesome paste content', api_paste_name: 'awesome paste name', api_paste_private: 1, api_paste_expire_date: '1d' }); var req = http.request({ host: 'pastebin.com', port: 80, path: '/api/api_post.php', method: 'post', headers: { 'content-type': 'multipart/form-data', 'content-length': query.length } }, function(res) { var data = ''; res.on('data', function(chunk) { data += chunk; }); res.on('end', function() { console.log(data); }); }); req.write(query); req.end();
console.log(query)
confirms string encoded , api_option there , set paste.
now, i've been searching forever on possible causes. tried setting encoding on write req.write(query, 'utf8')
because pastebin api mentions post must utf-8 encoded. rewrote thing on , on , re-consulted node http documentation many times.
i'm pretty sure missed here, because don't see how fail. have idea of have done wrong?
what you're creating isn't properly-formed multipart/form-data
request; looks more application/x-www-form-urlencoded
request. can tell pastebin's api (i've never used it) latter want, try changing content-type
it.
Comments
Post a Comment