我测试的时候返回状态吗为200,但是刷新页面没有出来我通过程序注入的评论,是怎么回事呢
这是我的代码,麻烦帮帮看看 var http = require('http') var querystring = require('querystring'); var postData = querystring.stringify({ 'content':'测试一下刚学的东西', 'cid':348 }) var options = { hostname:'www.imooc.com', port:80, path:'/course/docomment', metod:'POST', headers:{ 'Accept':'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding':'gzip, deflate', 'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,ja;q=0.2,sq;q=0.2', 'Connection':'keep-alive', 'Content-Length':postData.length, 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'Cookie':'/复制的cookie不会有错/', 'Host':'www.imooc.com', 'Origin':'http://www.imooc.com', 'Referer':'http://www.imooc.com/comment/348', 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', 'X-Requested-With':'XMLHttpRequest' } } console.log(postData.length); 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 (e){ console.log('评论完毕'); }) }) req.on('error',function(e){ console.log('errors:'+e.message) }) req.write(postData) req.end()
Status: 200
headers: {"server":"nginx","date":"Mon, 27 Jun 2016 12:23:24 GMT","content-type":"text/html; charset=utf-8","transfer-encoding":"chunked","connection":"keep-alive","vary":"Accept-Encoding, Accept-Encoding","expires":"Thu, 19 Nov 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
评论完毕