nodejs==如何实现评论功能

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"
Cookie:"imooc_uuid=23fb0fc6-ad6f-40d2-8667-8781e002bf04; imooc_isnew=2; imooc_isnew_ct=1448286380; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1448286401,1449758110,1450102551; loginstate=1; apsid=FiYjhlZDQzYjUyOTJmMDFjMTQ2YWYzYTVlOTk3ZWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIwMDUxMjY1NjUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjk2Mzk3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzNDIxOTEyODhAcXEuY29tAAAAAAAAAAAAAAAAAAAAAGY0ZjQ5MTNjZmNhOTFkNmRiZTBhNWJhZTc3NDVmZjMxaQcEVL71R1Y%3DOT; IMCDNS=0; cvde=566ecf1642040-14; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1450105415; PHPSESSID=2vl74j2nm4iosiemadrjuancb3; jwplayer.qualityLabel=é«æ¸"
Connection:"keep-alive"
Pragma:"no-cache"
Cache-Control:"no-cache"


//表单数据
mid:"8837"
time:"60.00200000000018"
learn_time:"417"

//消息头
 请求网址 :http://www.imooc.com/course/ajaxmediauser/
 请求方法:POST
 远程地址:116.213.120.40:80
 状态码:200  OK
 版本:HTTP/1.1
//评论功能
var http = require('http')
var querystring = require('querystring')

var postData = querystring.stingify({
    'content' : '我是来灌水的',
    'cid': 8837 //提交的ID  在表单数据:查看mid
})
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',
        'Cookie':'imooc_uuid=23fb0fc6-ad6f-40d2-8667-8781e002bf04; imooc_isnew=2; imooc_isnew_ct=1448286380; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1448286401,1449758110,1450102551; loginstate=1; apsid=FiYjhlZDQzYjUyOTJmMDFjMTQ2YWYzYTVlOTk3ZWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIwMDUxMjY1NjUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjk2Mzk3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzNDIxOTEyODhAcXEuY29tAAAAAAAAAAAAAAAAAAAAAGY0ZjQ5MTNjZmNhOTFkNmRiZTBhNWJhZTc3NDVmZjMxaQcEVL71R1Y%3DOT; IMCDNS=0; cvde=566ecf1642040-14; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1450105415; PHPSESSID=2vl74j2nm4iosiemadrjuancb3; jwplayer.qualityLabel=é«æ¸',
        '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()


转载于:https://my.oschina.net/newgoup/blog/544349

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值