課程
/前端開發(fā)
/Node.js
/進(jìn)擊Node.js基礎(chǔ)(一)
我按照視頻上的寫的代碼,但是總是報錯errorsocket hang up,請問誰知道這是什么原因?win10的系統(tǒng)。
2017-03-19
源自:進(jìn)擊Node.js基礎(chǔ)(一) 5-12
正在回答
抱歉,path是對的,content length應(yīng)該改成 postData.length?
你的path有問題,?path:'/course/docomment',
/** * Created by hp on 2017/3/19. */var http=require('http');var querystring=require('querystring');var postData=querystring.stringify({ ? 'content':'老師講的挺好', ? 'cid':348});var options={ ? ?hostname:'idcbgp.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', ? ? ? ?'Connection':'keep-alive', ? ? ? ?'Content-Length':'133', ? ? ? ?'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', ? ? ? ?'Cookie':'imooc_uuid=01708583-afe9-4af8-b0e4-70e126d49aea; imooc_isnew_ct=1476869310; PHPSESSID=d2oh48v48v6ase1l3fqv71c6t2; loginstate=1; apsid=Y2ZDhkNjgyOTgwZDYzY2JhOTUyZjBlNTViYmIyMTQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzk2MDIxNwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGM5Y2U3MTIxNDkwN2FmZTllODAzODBiZGRlMGFiODdi%2FAHOWPwBzlg%3DNW; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1489895554; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1489909296; IMCDNS=0; imooc_isnew=2; cvde=58ce00803afc4-146', ? ? ? ?'Host':'idcbgp.cn', ? ? ? ?'Origin':'http://idcbgp.cn', ? ? ? ?'Referer':'http://idcbgp.cn/comment/348', ? ? ? ?'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36', ? ? ? ?'X-Requested-With':'XMLHttpRequest' ? ?}};var req=http.request(options,function(res){ ? ?console.log('status+'+res.statusCode) ? ?res.on('data',function(chunk){ ? ? ? ?console.log('正在返回') ? ?}) ? ?res.on('end',function(){ ? ? ? ?console.log('評論完畢') ? ?})});req.on('error',function(e){ ? ?console.log('error'+ e.message)});req.write(postData);req.end();
這是代碼,請問有什么問題嗎?
舉報
本視頻教程帶你揭開Node.js的面紗,帶你走進(jìn)一個全新世界
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-05-16
抱歉,path是對的,content length應(yīng)該改成 postData.length?
2017-05-16
你的path有問題,?path:'/course/docomment',
2017-03-19
/**
* Created by hp on 2017/3/19.
*/
var http=require('http');
var querystring=require('querystring');
var postData=querystring.stringify({
? 'content':'老師講的挺好',
? 'cid':348
});
var options={
? ?hostname:'idcbgp.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',
? ? ? ?'Connection':'keep-alive',
? ? ? ?'Content-Length':'133',
? ? ? ?'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
? ? ? ?'Cookie':'imooc_uuid=01708583-afe9-4af8-b0e4-70e126d49aea; imooc_isnew_ct=1476869310; PHPSESSID=d2oh48v48v6ase1l3fqv71c6t2; loginstate=1; apsid=Y2ZDhkNjgyOTgwZDYzY2JhOTUyZjBlNTViYmIyMTQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzk2MDIxNwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGM5Y2U3MTIxNDkwN2FmZTllODAzODBiZGRlMGFiODdi%2FAHOWPwBzlg%3DNW; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1489895554; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1489909296; IMCDNS=0; imooc_isnew=2; cvde=58ce00803afc4-146',
? ? ? ?'Host':'idcbgp.cn',
? ? ? ?'Origin':'http://idcbgp.cn',
? ? ? ?'Referer':'http://idcbgp.cn/comment/348',
? ? ? ?'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36',
? ? ? ?'X-Requested-With':'XMLHttpRequest'
? ?}
};
var req=http.request(options,function(res){
? ?console.log('status+'+res.statusCode)
? ?res.on('data',function(chunk){
? ? ? ?console.log('正在返回')
? ?})
? ?res.on('end',function(){
? ? ? ?console.log('評論完畢')
? ?})
});
req.on('error',function(e){
? ?console.log('error'+ e.message)
});
req.write(postData);
req.end();