還是報錯??!
var http= require('http')
var querystring=require('querystring')
var postData=querystring.stringify({
? ?'content':'來測試一下啊啊啊',
? ?'cid':8837
})
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',
'Connection':'keep-alive',
'Content-Length':'140',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'PHPSESSID=fu0ht9n44qq1vubpbr7757hfl5; imooc_uuid=c147558b- e1aa-4ee0-be52-000348796b68; imooc_isnew_ct=1492754794; loginstate=1; apsid=k4OTA5MmFmMDYyZDYxZTYzNWJhNmQyMmY1ZDZlMWUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANDA4MTk2NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzOTMwNTIxODZAcXEuY29tAAAAAAAAAAAAAAAAAAAAAGEzYzc5NDExZTFkODk4MTk4Y2RjZWU5OWU2ZTVkODgwc7kBWXO5AVk%3DYT; last_login_username=393052186%40qq.com; channel=491b6f5ab9637e8f6dffbbdd8806db9b_phpkecheng; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1493098520,1493192913,1493199250,1493253843; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1493886814; imooc_isnew=2; cvde=58f9a16acff7b-570',
'Host':'www.xianlaiwan.cn',
'Origin':'http://www.xianlaiwan.cn',
'Referer':'http://www.xianlaiwan.cn/video/8837',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 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.header))
? ?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()
2017-05-04
請求的信息 是你登入的嗎? Cookie ? 是不是超時了 ?那個 是通信錯誤 ?Socket ?