今天刚接入熊掌号,由于我博客是nodejs做得,所有使用http模块做了一个自动推送新添加的文章到熊掌号。
我是使用的原生的http模块做得post请求,也可以使用其他第三方库请求,大同小异。
var http = require('http');
var bodyString = 'https://zhangwenbing.com/blog/ffmpeg/SJkrWTUVm';
var headers = {
'Content-Type': 'text/plain',
'Content-Length': bodyString.length
};
var options = {
host: 'data.zz.baidu.com',
port: 80,
path: '/urls?appid=xxxxxxx&token=xxxxxx&type=realtime',
method: 'POST',
headers: headers
};
var req = http.request(options, function (res) {
res.setEncoding('utf-8');
res.on('data', function (data) {
console.log(data);
});
// res.on('end', function (res) {
// console.log(res);
// });
// req.on('error', function (e) {
// // TODO: handle error.
// console.log('-----error-------', e);
// });
});
req.write(bodyString);
req.end();
如果这篇文章对你有所帮助,可以通过下边的“打赏”功能进行小额的打赏。
本网站部分内容来源于互联网,如有侵犯版权请来信告知,我们将立即处理。