状态码200,回复不显示?????
var https = require('https')
var querystring = require('querystring')
var postData = querystring.stringify({
'content': '试了很多次,程序没问题,评论不出现!!!',
'mid': 8837
})
var options = {
hostname: 'www.imooc.com',
port: 443, //http默认port是80,https默认port是443
path: '/course/docomment',
method: 'POST',
headers:{
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN',
'Cache-Control': 'no-cache',
'Connection': 'Keep-Alive',
'Content-Length': postData.length,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': 'loginstate=1; mc_marking=b587280c0c1c0e76c1092aa21406565a; imooc_isnew_ct=1519651037; imooc_isnew=2; apsid=VmYmFlMTEwYmEzMDhkYWM4NmNkNTA3Y2ExNzcyMGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANjE5NDAxNQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3NzY3Mjg2MDBAcXEuY29tAAAAAAAAAAAAAAAAAAAAAGY3YTg5OGIxYTA2MzliMWNhMTMxZWVjMjE2Mjg1MGRhMgmUWjIJlFo%3DZD; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1519651035,1519651119,1519734653,1519785715; last_login_username=776728600%40qq.com; mc_channel=syb6; imooc_uuid=054da5b5-6d99-495c-8f36-8e2d02698e31; cvde=5a9616f19adcc-7; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1519785721; PHPSESSID=a3dbbmbd452grgjssc4dpvsgk7',
'Host': 'www.imooc.com',
'Origin': 'https://www.imooc.com',
'Referer': 'https://www.imooc.com/video/8837',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299',
'X-Requested-With': 'XMLHttpRequest'
}
}
var req = https.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()
运行结果:
Status: 200
headers: {"server":"nginx","date":"Wed, 28 Feb 2018 03:34:33 GMT","content-type":"text/html; charset=utf-8","transfer-encoding":"chunked","connection":"keep-alive","vary":"Accept-Encoding","expires":"Thu, 19 No
v 1981 08:52:00 GMT","cache-control":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0","pragma":"no-cache","content-encoding":"gzip"}
true
object
评论完毕!
求指导!