精选圈子榜单优站
编程综合
编程综合
技术
20关注
编程技术记录、分享 ,记录你的编程生活点点滴滴!

【NodeJs】Http:client


var http = require('http');
var querystring = require('querystring');

var contents = {
        'name':'Nemo',
        'age':'23',
        'address':'beijing'
}

contents = querystring.stringify(contents);

var options = {
        'host':'localhost',
        'port':'3000',
        'method':'POST',
        'path':'/',
        'headers':{
                'Cotent-Type':'application/x-www-form-urlencoded',
                'Content-Length':contents.length
        }
};

var req = http.request(options,function (res){
        res.setEncoding('utf-8');
        res.on('data',function (data){
                console.log('获取到的后台返回数据');
                console.log(data);
        });
});

req.write(contents);
req.end();


  • 若文章侵犯了您的权益,请联系我们进行处理。

  • 2016-08-01
  • 3533阅读
评论