function form(callBack) { var data = { username: 'admin', password: "123" }; var postData = require('querystring').stringify(data); var options = { method: "POST", host: "test.xx.cn", port: 8001, path: "/api/MyApi/test1", headers: { "Content-Type": 'application/x-www-form-urlencoded', "Content-Length": postData.length } }; console.log( options ); var body = ''; var request = http.request( options, function(res) { // show results console.log('STATUS: ' + res.statusCode); res.setEncoding('utf8'); res.on('data', function(chunk) { body += chunk; console.log('BODY: ' + chunk); }); res.on('end', function(err) { console.log( ' complete.'); callBack(body); }); }); request.on("error", function(e) { console.log('upload Error: ' + e.message); }); request.write(postData); request.end(); } function data_(d){ console.log("获取返回数据:"+d); } form(data_);