nodejs实现评论盖楼

PC端评论接口:
多说: http://duoshuo.com/
畅言: http://changyan.kuaizhuan.com

//评论功能
var http = require('http')
var querystring = require('querystring')
var postData = querystring.stingify({
    'content' : '评论',
     //提交的ID  在表单数据:查看mid
    'cid': 8837
})
var options = {
    hostname: 'www.imooc.com',
    port:80,
    //路径 查看消息头: 请求网址
    path:'/course/ajaxmediauser', 
    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()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • nodejs 评论盖楼 PC端评论接口 1.畅言:http://changyan.kuaizhuan.com 2....
    crazy__stone阅读 400评论 0 0
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,589评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,268评论 19 139
  • 凌晨五点, 整个城市的星星都睡着了。 月亮也睡着了。 早行的路人, 挑着装满露珠的竹篓, 一前一后地, 慢慢地走。...
    C浅夕阅读 258评论 0 1
  • 时间的公平就是40元的表和40万元的表他的指针始终在同一个位置。就如同人,我们如此类似,我们又如此迥异。 2013...
    瘦到贴心阅读 436评论 5 10