http.get('http://path/to/image.jpg', function (res) {
var img = '';
res.on('data', function (buff) {
img += buff;
});
res.on('end', function () {
var data = querystring.stringify({
image: img.toString('base64'),
type: 'base64'
});
var opts = {
host: 'api.imgur.com',
path: '/3/image',
method: 'POST',
headers: {
'Authorization': 'Client-ID myId',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
}
};
var req = https.request(opts, function (res) {
res.on('data', function (buff) {
console.log(buff.toString());
});
});
req.end(data);
});
});
img
是我从 URL 下载的字符串。当我执行它时,我得到:
querystring.js:114
return encodeURIComponent(str);
^
URIError: URI malformed
如何正确地将帖子数据提交给Imgur?