Nemo

Nemo 关注TA

路漫漫其修远兮,吾将上下而求索。

Nemo

Nemo

关注TA

路漫漫其修远兮,吾将上下而求索。

  •  普罗旺斯
  • 负责帅就完事了
  • 写了1,496,113字

该文章投稿至Nemo社区   Js、Css、Html  板块 复制链接


[NodeJs]HTTP

发布于 2016/07/05 15:56 5,403浏览 0回复 3,162

var options = {
        hostname:'www.imooc.com',
        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',
                'Cache-Control':'no-cache',
                'Connection':'keep-alive',
                'Content-Length':postData.length,
                'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
                'Cookie':'imooc_uuid=10b0eaa8-2469-42bf-83a2-0ea075d48476; imooc_isnew=1; imooc_isnew_ct=1467618521; loginstate=1; apsid=MxOWIyZTQ0NGFiOWFiMTkwNWZiNDc1ZTEwOTBmNGYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzYwNDA2NgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxMTQwMTg4NzI0QHFxLmNvbQAAAAAAAAAAAAAAAAAAADRjNWFkNmY1YzY0NGRjODFlNjllMjUzN2UxYWMzYTBighZ6V4IWelc%3DMD; last_login_username=xxx%40qq.com; PHPSESSID=nkg5gk234h3dng0ed8uh8duop1; jwplayer.volume=80; jwplayer.qualityLabel=é«<98>æ¸<85>; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1467618522,1467681649; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1467701595; cvde=577b0b6fe1187-80',
                'Host':'www.imooc.com',
                'Origin':'http://www.imooc.com',
                'Pragma':'no-cache',
                'Referer':'http://www.imooc.com/video/8837',
                'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36',
                'X-Requested-With':'XMLHttpRequest'
        }
}

var req = http.request(options,function (res){
        console.log('status:'+res.statusCode);
        console.log('hreders:'+JSON.stringify(res.headers));

        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();

本文标签
 {{tag}}
点了个评