Nemo

Nemo 关注TA

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

Nemo

Nemo

关注TA

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

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

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


【NodeJs】Http:client

发布于 2016/08/01 22:11 2,967浏览 0回复 1,466

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

点赞(0)
点了个评