請大神看看這是個啥錯誤,謝謝!?。?/h1>

var?http?=?require('http')
var?querystring?=?require('querystring')
var?postData?=?querystring.stringify({
?'content':'期待后面的課程',
?'cid':'348'
})?
var?options?=?{
?hostname:'www.xianlaiwan.cn',
?port:80,
?path:'/course/docomment',
?method:'POST',
?headers:{
??'Accept':'application/json,?text/javascript,?*/*;?q=0.01',
??'Accept-Encoding':'gzip,?deflate',
??'Accept-Language':'en-US,en;q=0.8,xh-CN;q=0.6,zh;q=0.4',
??'Cache-Control':'no-cache',
??'Connection':'keep-alive',
????????'Content-Length':postData.length,
??'Content-Type':'application/x-www-form-urlencoded;?charset=UTF-8',
??'Cookie':'imooc_uuid=3b1abdc4-3362-42b2-b668-1cf0561917da;?imooc_isnew_ct=1496715442;?PHPSESSID=oi6sr43s3eom2s11iaalifs9e0;?loginstate=1;?apsid=c1ZTRhYjQ3NDI0MTUxNTkxNDhjNTJkNjRjZmQwN2MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjQ2Nzk2NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxMTUyNTA3NjIyQHFxLmNvbQAAAAAAAAAAAAAAAAAAADRmNjU1YjRjNDIzNGIyZDM2NTRiNWQ4NzE5YjVlZGNk5p83WeafN1k%3DMz;?last_login_username=1152507622%40qq.com;?IMCDNS=0;?Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1496715472,1496815996;?Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1496817699;?imooc_isnew=2;?cvde=5937997f27536-41',
??'Host':'www.xianlaiwan.cn',
??'Origin':'http://www.xianlaiwan.cn',
??'Referer:http':'//www.xianlaiwan.cn/comment/348',
??'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',
??'X-Requested-With':'XMLHttpRequest'
?}
}
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('評論完畢')
?})
?res.on('error',function(e)?{
??console.log('Error:?'+?e.message)
?})
?req.write(postData)
?req.end()
})
var?http?=?require('http') var?querystring?=?require('querystring') var?postData?=?querystring.stringify({ ?'content':'期待后面的課程', ?'cid':'348' })? var?options?=?{ ?hostname:'www.xianlaiwan.cn', ?port:80, ?path:'/course/docomment', ?method:'POST', ?headers:{ ??'Accept':'application/json,?text/javascript,?*/*;?q=0.01', ??'Accept-Encoding':'gzip,?deflate', ??'Accept-Language':'en-US,en;q=0.8,xh-CN;q=0.6,zh;q=0.4', ??'Cache-Control':'no-cache', ??'Connection':'keep-alive', ????????'Content-Length':postData.length, ??'Content-Type':'application/x-www-form-urlencoded;?charset=UTF-8', ??'Cookie':'imooc_uuid=3b1abdc4-3362-42b2-b668-1cf0561917da;?imooc_isnew_ct=1496715442;?PHPSESSID=oi6sr43s3eom2s11iaalifs9e0;?loginstate=1;?apsid=c1ZTRhYjQ3NDI0MTUxNTkxNDhjNTJkNjRjZmQwN2MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjQ2Nzk2NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxMTUyNTA3NjIyQHFxLmNvbQAAAAAAAAAAAAAAAAAAADRmNjU1YjRjNDIzNGIyZDM2NTRiNWQ4NzE5YjVlZGNk5p83WeafN1k%3DMz;?last_login_username=1152507622%40qq.com;?IMCDNS=0;?Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1496715472,1496815996;?Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1496817699;?imooc_isnew=2;?cvde=5937997f27536-41', ??'Host':'www.xianlaiwan.cn', ??'Origin':'http://www.xianlaiwan.cn', ??'Referer:http':'//www.xianlaiwan.cn/comment/348', ??'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', ??'X-Requested-With':'XMLHttpRequest' ?} } 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('評論完畢') ?}) ?res.on('error',function(e)?{ ??console.log('Error:?'+?e.message) ?}) ?req.write(postData) ?req.end() })
2017-08-19
異常說的很明確,你的header name 'Referer:http'不是有效的,應該改成?'Referer':'http//www.xianlaiwan.cn/comment/348'
2017-06-08
這段要放在外面,不是在回調函數里,還有是req的error事件不是res。