node js實現(xiàn)評論功能

node js 實現(xiàn)評論

//評論功能 var http = require('http') var querystring = require('querystring') var postData = querystring.stingify({ 'content' : '我是來灌水的', 'cid': 8837 //提交的ID 在表單數(shù)據(jù):查看mid }) var options = { hostname: 'www.imooc.com', port:80, path:'/course/ajaxmediauser', //路徑 查看消息頭: 請求網(wǎng)址 method:'POST', headers:{ 'Host':'www.imooc.com', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0', 'Accept':'application/json, text/javascript, */*; q=0.01', 'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding':'gzip, deflate' 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With':'XMLHttpRequest', 'Referer':'http://www.imooc.com/video/8837', 'Content-Length':'46', 'Connection':'keep-alive', 'Pragma':'no-cache', 'Cache-Control':'no-cache' } } 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()
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容