首頁 > web前端 > js教程 > 實例詳解Nodejs 保存 payload 發送過來的檔案_node.js

實例詳解Nodejs 保存 payload 發送過來的檔案_node.js

WBOY
發布: 2016-05-16 15:19:56
原創
1679 人瀏覽過

1:接受文件

http://stackoverflow.com/questions/24610996/how-to-get-uploaded-file-in-node-js-express-app-using-angular-file-upload

可以用下列的第三方函式庫

•busboy and connect-busboy
•multiparty and connect-multiparty
•formidable
•multer

2:儲存檔案

ps:nodejs get/request

灌水評論範例:

var http = require('http');
var querystring = require('querystring');
var postData = querystring.stringify({
content: '不错不错',
cid: 348
});
var options = {
hostname: 'www.imooc.com',
port: 80,
path: '/course/docomment',
method: 'POST',
headers:{
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.8',
'Connection':'keep-alive',
'Content-Length':postData.length,
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'imooc_uuid=791e8f39-5d06-433a-831f-909fa85acdd3; imooc_isnew_ct=1452475309; IMCDNS=0; loginstate=1; apsid=A0NWQzM2RkMzM2NDk0NWFkOTc5NmQzYzBkNTUyMGMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjc0Njc4MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADBlY2Y5ZjJiZGNjZTFlZTJmMjkwZTE2Y2M4YWE4MWE49QOTVvUDk1Y%3DZD; PHPSESSID=1uunfnq1rdhup7tudcre36l8h1; jwplayer.qualityLabel=高清; cvde=569454113f947-13; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1452475311,1452561427; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1452579983; imooc_isnew=2',
'Host':'www.imooc.com',
'Origin':'http://www.imooc.com',
'Referer':'http://www.imooc.com/comment/348',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
}
var req = http.request(options, function(res) {
console.log('Status: ' + res.statusCode);
console.log('headers: ' + JSON.stringify(res.headers));
res.on('data', function(chunk) {
console.log(Buffer.isBuffer(chunk));
console.log(typeof chunk);
});
res.on('end', function() {
console.log('评论完毕');
});
});
req.on('error', function(e) {
console.log('Error: ' + e.message);
});
req.write(postData);
req.end();
登入後複製

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板