為什么我運行這個js文件總是提示語法錯誤?貌似無法識別字符長度,但是怎么修改呢?
//運行結果如下
源代碼如下
var?http=require('http') var?querystring?=?require('querystring') var?postData?=querystring.stringify({ 'content':'光陰如梭', 'mid':2404 }) 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':'zh-CN,zh;q=0.8,en;q=0.6', 'Cache-Control':'no-cache', 'Connection':'keep-alive', 'Content-Type':'application/x-www-form-urlencoded;?charset=UTF-8' 'Content-Length':postData.length, 'Cookie':'imooc_uuid=2bb7fba3-edd3-4d93-8155-65fb56a50b38;?imooc_isnew_ct=1473809150;?last_login_username=geasstry%40163.com;?PHPSESSID=989tf3nh4gddrevd1tr64vhd63;?jwplayer.qualityLabel=è???;?loginstate=1;?apsid=liYTc5NDYzOTQ5MWNkZTA3N2VmYjZlOGZhYjk3ZWUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzA3NzU3MwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGJhNGY0MTNiMWQxYjZlYjY2MDNjNGE5OWNhODRlYWRmH7XcVx%2B13Fc%3DYT;?IMCDNS=0;?Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1473994315,1474067553,1474071933,1474079045;?Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1474082091;?imooc_isnew=2;?cvde=57dca9438bee2-21' 'Host':'www.xianlaiwan.cn' 'Origin':'http://www.xianlaiwan.cn' 'Referer':'http://www.xianlaiwan.cn/video/2404' 'User-Agent':'Mozilla/5.0?(Windows?NT?10.0;?WOW64)?AppleWebKit/537.36?(KHTML,?like?Gecko)?Chrome/50.0.2661.95?Safari/537.36?Core/1.50.1233.400?QQBrowser/9.5.9092.400' '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();
2016-09-18
準確來說,options對象里每個鍵值對末尾要加逗號
2016-09-18
你上面那個鍵值對忘記加逗號了