nodejs 評(píng)論蓋樓
PC端評(píng)論接口
1.暢言:http://changyan.kuaizhuan.com
2.多說(shuō):http://duoshuo.com/
Demo
//評(píng)論功能
var http = require('http')
var querystring = require('querystring')
var postData = querystring.stingify({
'content' : '讓學(xué)習(xí)成為一種習(xí)慣',
'cid': cid //提交的ID 在表單數(shù)據(jù):查看mid
})
var options = {
hostname: 'http://www.itxdh.com/',
port:80,
path:'/course/ajaxmediauser', //路徑 查看消息頭: 請(qǐng)求網(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.itxdh.com/cid',
'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('評(píng)論成功所森!')
})
})
req.on('error', function(e){
console.log('Error:' + e.message)
})
req.write(postData)
req.end()
思路:
第一步:建數(shù)據(jù)庫(kù)表,這個(gè)表需要有ID及父ID.
第二步:添加回復(fù)
第三步:查詢回復(fù)焕济,并以蓋樓方式顯示(循環(huán)查詢)。